我有以下 Firestore 结构和一种从数据库获取用户提要的方法。
我需要像这样链接我的流
首先来自 User/FeedIDs 集合的所有提要 ID
然后对于每个 feedID,获取 feed 详细信息的文档并返回到它们的列表。
我可以找到解决此问题的方法,因为toList()
它不起作用或我做错了什么。
// User Collection
- User
- RandomDocumentID
- Feed
- FeedIDasDocumentID
- field1
- field2
.
.
// Feed Collection
- Feed
- RandomDocumentID
- field1
- field2
.
.
// Method in my repository to get feed for User
Observable<Feed> getCurrentUserFeed(String uid) {
return Observable(Firestore.instance
.collection('User')
.document(uid)
.collection("FeedIDs")
.snapshots()
.expand((snapshots) => snapshots.documents)
.map((document) => UserFeed.fromMap(document.data))
)
.flatMap((userFeed) => Firestore.instance
.collection("Feed")
.document(userFeed.id)
.snapshots()
)
.map((document) => Feed.fromMap(document.data));
// ????
// I tried to put .toList() and of the stream but it is not working,
// i wanna return List<Feed> instead of every single feed object
}
// in my BLoC
// I had to do that because I could acquire to get streams elements as a list
//
List<Feed> feedList = List();
FirebaseUser user = await _feedRepository.getFirebaseUser();
_feedRepository.getCurrentUserFeed(user.uid).listen((feed) {
feedList.add(feed);
dispatch(UserFeedResultEvent(feedList));
};
如果有任何其他链接方法,将非常感谢分享。谢谢