【发布时间】:2020-12-27 05:24:00
【问题描述】:
我想在以下 forEach 块结束时刷新小部件的状态。但问题是,在 for 循环停止执行之前,我的小部件会自行重建它,即它不会等待它执行然后刷新。
代码:-
publicQuicksDocuments.forEach((element) async{
if(element.postIdList.isNotEmpty)
{
DocumentSnapshot doc=await postsReference.document(element.id).collection('userPosts').document(element.postIdList.last).get();
element.postIdList.removeLast();
postList.add(Post.fromDocument(doc));
}
else
{
publicPostsDocuments.remove(element);
}
}); //After this for block overs then below code should execute and refresh the state
postList.shuffle();
setState(() {
loading=false;
});
请阅读上述代码中的注释。
【问题讨论】:
-
改用
Future.forEach
标签: firebase flutter dart google-cloud-firestore