如何在flutter firestore的同一個檔案記憶體儲一個檔案的id
如何在flutter firestore的同一個檔案記憶體儲一個檔案的id?
我得到的配方ID是空的
。Future updateRecipeData(RecipeModel recipeModel) async {
await recipeDataCollection.doc().set({
rRecipeTitle: recipeModel.title,
rRecipeBundleName: recipeModel.recipeBundleName,
rCookingTime: recipeModel.cookingTime,
rDateTime:recipeModel.dateTime。
rImgPath:recipeModel.imgPath。
rIngredients: recipeModel.配料。
rNumOfLikes:recipeModel.numOfLikes。
rPreparation:recipeModel.preparation。
rServings:recipeModel.servings。
});
print('Data TRANSFORMED'/span>)。
}
List<RecipeModel> getRecipes(QuerySnapshot snapshot) {
return snapshot.docs.map((doc) {
return RecipeModel(
title: doc.data()[rRecipeTitle],
cookingTime: doc.data()[rCookingTime],
imgPath: doc.data()[rImgPath],
成分。List.from(doc.data()[rIngredients])。
準備作業。List.from(doc.data() [rPreparation])。
numOfLikes: doc.data()[rNumOfLikes]。
dateTime: doc.data()[rDateTime],
servings: doc.data()[rServings],
recipeBundleName: doc.data()[rRecipeBundleName]。
recipeId: doc.id,
);
}).toList()。
}
Stream<List<RecipeModel>> get recipeData {
return recipeDataCollection.snapshots().map(getRecipes)。
}
這是我想把doc id存盤在recipeid里面的代碼。
RECIPE模型代碼
。
class RecipeModel{
String title, imgPath, recipeBundleName, recipeId;
String cookingTime, servings;
int numOfLikes。
String dateTime;
List<String> ingredients, preparation;
配方模型({
this.title,
this.coatingTime,
this.imgPath,
this.recipeBundleName,
this.servings,
this.numOfLikes,
this.dateTime,
this. ingredients,
this.preparation,
this.recipeId。
});
我共享了recipe模型,并有recipeId來存盤同一檔案中的id。
uj5u.com熱心網友回復:
你能分享一下這些代碼嗎?為了列印同一個檔案的id,你需要在代碼中創建id,并在設定或更新時發送它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/325747.html
標籤:


