Flutter将多个FireStore流与Rxdart结合

问题描述 投票:2回答:1

我想我需要将其合并到某个位置,但是我无法确定如何以及在哪里。我要在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));
      });
    });
  }
flutter dart stream observable rxdart
1个回答
0
投票

如果合并流,则StreamBuilder将仅显示合并流中的LAST事件。我相信你可以做这样的事情:

// snapshotList will be your AsyncSnapshot. snapshotList.data will be your List<QuerySnapshot>

StreamBuilder<List<QuerySnapshot>>(
    stream: streamList,
    builder: (BuildContext context, AsyncSnapshot<List<QuerySnapshot>> snapshotList) {
        snapshotList.data.forEach((document) {
            return something
        }
    }
)

让我知道是否有帮助

© www.soinside.com 2019 - 2024. All rights reserved.