【发布时间】:2020-09-12 19:26:47
【问题描述】:
我在flutter中有一个流,它从firestore数据库批量请求项目,合并它们并返回合并。代码如下。
Stream<List<Memo>> get memos {
// list of streams to be merged
List<Stream<List<Memo>>> streams = [];
// get list of friend userids
Firestore.instance.collection("users").document(userid).collection("friends").snapshots().map(_snapshotToStringList).listen((friends){ // add where confirmed == true to this
// break list into chunks of ten
for (var i = 0; i < friends.length; i++) {
// query post list for each chunk of 10 and add to stream list
streams.add(Firestore.instance.collection("memos").where("userid", isEqualTo: friends.sublist(i, i + 1)).snapshots().map(_snapshotToMemoList));
}
print(streams);
// merge steam list
});
print(streams);
return StreamGroup.merge(streams);
}
问题是函数在流返回必要的值之前终止,并将它们添加到要合并和返回的流列表中,从而导致返回空值。我无法在流函数中放置等待语句,因此我不确定如何在最终返回之前等待内部流完成。感谢您提供解决此问题的任何和所有建议。
【问题讨论】:
-
你应该看看this question
标签: firebase flutter dart google-cloud-firestore stream