gpt4 book ai didi

Flutter 将多个 FireStore 流与 Rxdart 结合

转载 作者:行者123 更新时间:2023-12-03 17:47:49 33 4
gpt4 key购买 nike

我想我需要在某个地方将它合并在一起,但我不知道如何以及在哪里。我想在 StreamBuilder 中使用?我把你带到这里等着你的帮助..

getCombinedMatches(uid) {
return Firestore.instance
.collection('matches')
.where('match', arrayContains: uid)
.snapshots()
.map((convert) {
return convert.documents.map((f) {
Observable<Matches> match = f.reference
.snapshots()
.map<Matches>((document) => Matches.fromMap(document.data));
Observable<User> user = Firestore.instance
.collection("users")
.document(uid)
.snapshots()
.map<User>((document) => User.fromMap(document.data));

Observable<Message> message = Firestore.instance
.collection('matches')
.document(f.documentID)
.collection("chat")
.orderBy('dater', descending: true)
.limit(1)
.snapshots()
.expand((snapShot) => snapShot.documents)
.map<Message>((document) => Message.fromMap(document.data));

return Observable.combineLatest3(match, user, message,
(matches, user, message) => CombinedStream(matches, user, message));
});
});
}

最佳答案

添加此代码最后一次操作

getCombinedMatches(uid) {
return Observable(Firestore.instance
.collection('matches')
.where('match', arrayContains: uid)
.snapshots())
.map((convert) {
return convert.documents.map((f) {
Stream<Matches> match = f.reference
.snapshots()
.map<Matches>((document) => Matches.fromMap(document.data));
Stream<User> user = Firestore.instance
.collection("users")
.document(uid)
.snapshots()
.map<User>((document) => User.fromMap(document.data));

Stream<Message> message = Firestore.instance
.collection('matches')
.document(f.documentID)
.collection("chat")
.orderBy('dater', descending: true)
.limit(1)
.snapshots()
.expand((snapShot) => snapShot.documents)
.map<Message>((document) => Message.fromMap(document.data));

return Observable.combineLatest3(match, user, message,
(matches, user, message) => CombinedStream(matches, user, message));
});
}).switchMap((observables) {
return observables.length > 0
? Observable.combineLatestList(observables)
: Observable.just([]);
});

}

关于Flutter 将多个 FireStore 流与 Rxdart 结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59109855/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com