flutter - 在 Streambuilder 中的集合上使用 where() 不断返回 null
问题描述
我试图在集合中找到符合特定条件的所有文档,并将其保存在 Streambuilder 中,以便我可以使用它返回的所有文档中的数据创建一个表。但是我在 Streambuilder 中的流一直为我在 Flutter 中的查询返回 null。我在 Python 中尝试了相同的查询,它返回了正确的文档。在流构建器中不可能有 where 查询吗?作为参考,这是一个网络应用程序。
这是我的代码
class ContainerCustomerTable extends StatefulWidget {
final company;
ContainerCustomerTable({this.company});
@override
_ContainerCustomerTableState createState() => _ContainerCustomerTableState();
}
class _ContainerTableState extends State<ContainerCustomerTable> {
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection(widget.company).where('some_criteria', isEqualTo: true).snapshots(),
builder: (context, snapshot) {
print(snapshot);
QuerySnapshot docSnapshot = snapshot.data;
if (docSnapshot != null) {
return Text('test1');
} else{
return LoadingIndicator();
}
}
);
我正在打印快照只是为了检查它返回的内容,它给了我这个
AsyncSnapshot<QuerySnapshot>(ConnectionState.active, null, [cloud_firestore/unknown] NoSuchMethodError: invalid member on null: 'includeMetadataChanges')
因此它为该查询返回 null,但在 python 中的相同查询再次产生正确的结果。我究竟做错了什么?
作为记录,当我运行以下命令时,它可以工作:
FirebaseFirestore.instance.collection(widget.company).doc('some_doc').snapshots()
但由于某种原因,当我只是在集合或位置上运行快照时,我收到上面发布的错误
解决方案
我想到了。我的语法很好,是 firestore js 包错误。如果您将 firestore 用于 Web 应用程序,请在您的 web/index.html 中使用此版本:
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
不是最后一个版本 8.0.2,当我降级时,一切都按预期工作。
推荐阅读
- c# - 如何在将XML中的子项列表解析为c#中的对象时保留父元素引用
- python - 在字典中检查多个 if 条件的优雅方法
- python - 在 Python 中使用多线程创建 excel 文件
- android-studio - Android Studio 64 位内联 ARM 程序集
- azure-devops - 代理离线时建立队列
- version - 如何从待处理的更改列表中删除具有特定扩展名的文件?
- javascript - 尝试通过单击按钮显示图像会引发“加载资源失败:服务器响应状态为 500(内部服务器错误)”
- java - 在 junit 上看不到存储库中的数据
- php - Wordpress 选项树值未更新
- mysql - 在 MySql 中插入数据时,单引号的字符串中出现错误