flutter - 从Firestore Collection构建的Flutter Stream Builder中的多个案例

标签 flutter dart google-cloud-firestore

我找不到文档或示例,说明如何在Firestore Collection返回的Flutter Stream Builder中使用多个where子句。

波纹管查询工作

      Firestore
          .instance
          .collection (collectionName)
          .where      ("index",   arrayContains:  search)
          .orderBy    ('date',    descending:     true  )
          .snapshots()

但是如果我添加一个额外的where子句,则返回零
      Firestore
          .instance
          .collection (collectionName)
          .where      ("index",   arrayContains:  search)
          .where      ('allowed_roles', arrayContains: GlobalVars.userRole.toString() )
          .orderBy    ('date',    descending:     true  )
          .snapshots() 

Firebase文档中的复合查询示例看起来与上面类似,但是缺少Flutter或Dart示例。

编辑:
我也尝试过将查询构建模式作为变通办法,但它也不起作用。 Flutter确实不希望arrayContains子句不止一次。
  CollectionReference collectionRef = Firestore.instance.collection (collectionName);
  Query p =  collectionRef.where      ('allowed_roles', arrayContains: "3");
  Query q =  p.where      ('index', arrayContains: "Dan");

  Stream s = q.snapshots(); 

我在这里所缺少的是程序员应该针对逻辑上的“逻辑与”解决方案,该解决方案是一个非常基本的方程式,并且很难坚持使用此功能。

最佳答案

查询中不能有两个arrayContains过滤器:

      .where      ("index",   arrayContains:  search)
      .where      ('allowed_roles', arrayContains: GlobalVars.userRole.toString() )

根据documentation,一次仅支持一个arrayContains。这是Firestore的局限,无法更改。该查询肯定会产生错误-您应该添加代码来检查错误,而不是盲目地假设它成功。

关于flutter - 从Firestore Collection构建的Flutter Stream Builder中的多个案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61916346/

相关文章:

java - 使用 Firestore 集合中的图像填充 RecyclerView

flutter : How to hide AlertDialog

flutter - 更新到 Flutter 1.12.13 后,TextField 提示/输入文本在没有 prefixIcon 的情况下未居中

dart pub 未将符号链接(symbolic link)设置为本地包

flutter - 从flutter的api滚动时如何加载数据

android - Flutter cloud_firestore 包导致应用崩溃

python - 如何使用 Python 在 Firestore 中下载大型集合而不会出现 503 错误?

flutter - 如何使用SizedBox在其自己的类中包装派生的RaisedButton对象?

json - 如何在flutter中获取JSON映射的第一个值?

flutter - Flutter/Dart使用ListView.builder为每个x项构建一个不同的小部件