使用另一个流中的一个流进行扑动

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

我有一个将firebase用作数据库的flutter项目。我试图通过流获取文档名称列表,将其分成10组,以解决Firebase中.where()函数的最大10个比较问题,然后使用.where()进行批处理请求并将它们合并。

我知道的问题是:

  1. friends.length不能作为循环中的数字使用,因为它的类型为future

  2. 由于我不了解的原因,无法将firestore查询返回添加到流列表中(“无法将参数类型'Query'分配给参数类型'Stream'。”

  3. 。where()期望1个位置参数,但我给它3个,尽管这是Firestore文档所说的,我应该这样做

  4. StreamGroup未定义

  Stream<List<Memo>> get memos {
    // create list of streams
    List<Stream> streams = [];
    // Get list of friend userids
    var friends = Firestore.instance.collection("users").document(userid).collection("friends").snapshots().map(_snapshotToStringList);
    // split friend userid list into chunks of 10
    for (var i = 0; i < friends.length; i += 10) {
      // query database for each chunk of 10 and add to stream list
      streams.add(Firestore.instance.collection("memos").where("userid", "in", friends.sublist(i, i+10)));
    }
    // merge and return stream list
    return StreamGroup.merge(streams);
  }

任何人和所有建议都值得赞赏

firebase flutter dart google-cloud-firestore stream
1个回答
0
投票
Stream<List<Memo>> get memos {

List<Stream> streams = [];
Firestore.instance.collection("users").document(userid).collection("friends").snapshots().map(_snapshotToStringList).listen((friends){
                for (var i = 0; i < friends.length; i += 10) {
                  // query database for each chunk of 10 and add to stream list
                  streams.add(Firestore.instance.collection("memos").where("userid", isEqualTo: friends.sublist(i, i+10)));
                }
        });


                return StreamGroup.merge(streams);
              }


use this code
© www.soinside.com 2019 - 2024. All rights reserved.