【发布时间】:2021-12-16 10:17:50
【问题描述】:
我有下面的 Future 返回一个字符串列表,而不是我想返回具有相同文档 ID 列表的 Stream String List,我该怎么做?
Future<List<String>> getFollowingUidList(String uid) async{
final QuerySnapshot result = await FirebaseFirestore.instance.collection('following').doc(uid).collection('user_following').get();
final List<DocumentSnapshot> documents = result.docs;
List<String> followingList = [];
documents.forEach((snapshot) {
followingList.add(snapshot.id);
});
return followingList;
}
【问题讨论】:
-
而不是
[...].get(),它返回一个Future,使用[...].snapshots(),它返回一个Stream -
@pskink 如何从 Stream
流式传输文档 ID snapshots = FirebaseFirestore.instance.collection('following').doc(uid).collection('user_following').snapshots() ; -
你需要“修改”你原来的
Stream,更多在这里:dart.dev/tutorials/language/streams#modify-stream-methods
标签: firebase flutter google-cloud-firestore