小编Rkd*_*dio的帖子

Flutter Firebase 使用合并最新流合并流列表并在 StreamBuilder 上显示

我有一个这样的流的组合列表;

var Ref1 = _firestore
      .collectionGroup("Posts")
      .where('postID', whereIn: List1)
      .snapshots();
  var Ref2 = _firestore
      .collectionGroup("Posts")
      .where('postID', whereIn: List2)
      .snapshots();
  var Ref3 = _firestore
      .collectionGroup("Posts")
      .where('postID', whereIn: List3)
      .snapshots();
  
  List<Stream<QuerySnapshot>> combineList = [Ref1, Ref2, Ref3];
Run Code Online (Sandbox Code Playgroud)

combineList通过这种方法,我合并了来自;的流。

var totalRef = Rx.combineLatest(
    combineList, (list) => (list as Iterable<Iterable>).flattened);
Run Code Online (Sandbox Code Playgroud)

然后我用totalRef里面的StreamBuilder

StreamBuilder<QuerySnapshot>(
                      stream: totalRef,
                      builder:
                          (BuildContext context, AsyncSnapshot asyncsnapshot) {
                        if (asyncsnapshot.hasError) {
                          return Center(
                            child: Text("Error"),
                          );
                        } else {
                          if (asyncsnapshot.hasData) {
                            List<DocumentSnapshot> listOfDocumentSnapshot =
                                asyncsnapshot.data.docs;
                            return ListView.builder( …
Run Code Online (Sandbox Code Playgroud)

firebase flutter google-cloud-firestore

-1
推荐指数
1
解决办法
769
查看次数

标签 统计

firebase ×1

flutter ×1

google-cloud-firestore ×1