firebase - Flutter firebase 流有数据但返回 null
问题描述
我有一个问题,Firestore 中有一些文档具有相同的位置,并且在打印出正确的字符串时,位置被正确传递,但我的 StreamBuilder 总是在 if 条件下执行 noData 函数。
Streambuilder 看起来像这样:
StreamBuilder(
stream: FilterFirebase().relatedLocationFilter(
eventDocument["location"], eventDocument["id"]),
builder: (BuildContext ctx,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData ||
snapshot.data.docs.isEmpty) {
return NoDataRelatedLocation();
} else {
return new RelatedLocationListing(
relatedLocationList: snapshot.data.docs,
);
}
},
)
我的relatedLocationFilter 看起来像这样:
relatedLocationFilter(String location, String id) {
print(location);
print(id);
return FirebaseFirestore.instance
.collection("events")
.where("location", isEqualTo: location)
.where("id", isNotEqualTo: id)
.snapshots();
}
安全规则是正常的,没有 where 过滤器的代码工作正常。
更新:
日志:
颤振:Tj4EB68R1CwBYKPfWzcm
扑:米高梅宴会厅
颤振:1
Firestore 文档:
解决方案
这是正确的期望结果。因此,尽管您stream
返回了正确的值,但流构建器在您stream
获取数据之前首先获取 null。因此,如果您不想在获得真实数据NoDataRelatedLocation
之前显示stream
,则应放置initialData
流构建器的参数。
推荐阅读
- gnu-parallel - GNU Parallel 如何处理多线程作业?
- javascript - 从web api响应c#下载带有angularJS的filesaver.js文件
- java - 获取类定义中泛型的参数化类型
- android - 如何使用 Flutter 将整数存储到 Firestore
- android - Ionic 4 应用程序未在 Android 9 和低于 7 的 Android 版本中运行
- excel - 为工作簿密码保护调试 VBA
- vue.js - 嵌套 Nuxt 实例
- javascript - 将椭圆曲线加密与 OpenSSL 一起用于 php 和 javascript
- c# - 如何从 PDF 中提取所有值?
- c# - 仅接收 asc 或 desc 的 sortBy 和 sortorder 的有效性如何?