[英]Flutter firebase stream has data but returns null
I have a Problem there are some documents in Firestore that have the same location and the location gets passed correctly as it prints out the right string, but my StreamBuilder always executes the noData function in the if condition.我有一个问题 Firestore 中的一些文档具有相同的位置,并且在打印出正确的字符串时,该位置被正确传递,但我的 StreamBuilder 总是在 if 条件下执行 noData function。
The Streambuilder looks like this: 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,
);
}
},
)
My relatedLocationFilter looks like this:我的relatedLocationFilter 看起来像这样:
relatedLocationFilter(String location, String id) {
print(location);
print(id);
return FirebaseFirestore.instance
.collection("events")
.where("location", isEqualTo: location)
.where("id", isNotEqualTo: id)
.snapshots();
}
The security rules are normal and the code without the where filters is working fine.安全规则是正常的,没有 where 过滤器的代码工作正常。
Update:更新:
Logs:日志:
flutter: Tj4EB68R1CwBYKPfWzcm flutter:Tj4EB68R1CwBYKPfWzcm
flutter: MGM Banquet Hall flutter:米高梅宴会厅
flutter: 1 flutter:1
Firestore Docs: Firestore 文档:
That is the correct desired result.这是正确的期望结果。 So though your
stream
returns the proper value, the stream builder first gets null before your stream
gets data.因此,尽管您的
stream
返回了正确的值,但 stream 构建器首先获得 null 在您的stream
数据之前。 So if you don't want to show NoDataRelatedLocation
before your stream
gets real data, you should put initialData
param of your stream builder.因此,如果您不想在
stream
获取真实数据之前显示NoDataRelatedLocation
,则应放置 stream 构建器的initialData
参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.