值得注意的是,我的应用程序可以按预期运行,但似乎会不断重建,而不是在进行更改时重建。 如果删除getAllFavoriteRecipes函数,则除非来回导航,否则该应用程序将不会更新。即刷新状态。
body: StreamBuilder(
stream:
Firestore.instance.collection('users').document(uid).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Loading();
} else {
favoriteIDs = snapshot.data['favorites'];
getAllFavoriteRecipes(recipeNotifier, favoriteIDs);
获取所有收藏的食谱。
getAllFavoriteRecipes(RecipeNotifier recipeNotifier, favoriteIDs) async {
//print('Service FavoriteIDs: $favoriteIDs');
QuerySnapshot snapshot = await Firestore.instance
.collection('recipes')
.where('recipeID', whereIn: favoriteIDs)
.getDocuments();
List<RecipeList> _recipes = [];
snapshot.documents.forEach((document) {
RecipeList recipe = RecipeList.fromMap(document.data);
_recipes.add(recipe);
});
recipeNotifier.recipeList = _recipes;
}
这是一条日志,显示在添加/删除项目时正确重建了该应用程序,但是该应用程序也在不断重建。
I/flutter (13220): Rebuilt
I/flutter (13220): [yGkfj33jruv7acpVkakVDecgW, dYWcxwn66N6Tpc4GBX5Y67SGS, WN73rDVgxS3HkKF8X2YJTuEwv]
I/flutter (13220): removed
I/flutter (13220): Rebuilt
I/flutter (13220): [yGkfj33jruv7acpVkakVDecgW, dYWcxwn66N6Tpc4GBX5Y67SGS, WN73rDVgxS3HkKF8X2YJTuEwv]
I/flutter (13220): Rebuilt
I/flutter (13220): [yGkfj33jruv7acpVkakVDecgW, WN73rDVgxS3HkKF8X2YJTuEwv]
I/flutter (13220): Rebuilt
I/flutter (13220): [yGkfj33jruv7acpVkakVDecgW, WN73rDVgxS3HkKF8X2YJTuEwv]
I/flutter (13220): Rebuilt