简体   繁体   English

Flutter firebase stream 有数据但返回 Z37A6259CC0C1DAE299A7866489DFFBD0

[英]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.

相关问题 Firebase 在flutter中检索数据返回一个null的字符串 - Firebase data retrieval in flutter returns a null string StreamBuilder 返回数据,而它 Query(stream) 实际上在 flutter 中没有数据 - StreamBuilder returns data while it Query(stream) actually has no data in flutter Flutter Firebase Auth Anonymous currentUser() 返回 null - Flutter Firebase Auth Anonymous currentUser() returns null Flutter Firebase 身份验证 currentUser() 返回 null - Flutter Firebase Authentication currentUser() returns null 来自特定类型数据的 Flutter 和 Firebase 流 - Flutter & Firebase stream from certain type of data 使用 Stream 检索数据<querysnapshot>在 Firebase 和 Flutter</querysnapshot> - Retrieving Data with Stream<QuerySnapshot> in Firebase with Flutter Stream/Bloc/Repository/Firebase 数据流 Flutter - Stream/Bloc/Repository/Firebase data flow Flutter Flutter:提供者和 Firebase | 来自 Firestore 数据(映射)的 Object 列表从提供者返回 null - Flutter: Provider and Firebase | List of Object from Firestore Data (mapped) returns null from Provider Flutter Firebase Auth返回null,然后返回正确的值 - Flutter Firebase Auth returns null, then returns the correct value Firebase 实时数据库 Flutter stream 从不返回问题 - Firebase RealTime database Flutter stream never returns problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM