【问题标题】:Flutter Firebase not returning correct queried documentsFlutter Firebase 未返回正确的查询文档
【发布时间】:2020-07-05 08:35:10
【问题描述】:

我想在 'communities' 集合中查找所有文档,其中用户的 id 包含在 'members' 数组中。 但是我的 firebase 查询只是返回“社区”集合中的所有文档,而不仅仅是我查询的文档。

Stream<QuerySnapshot> get userCommunities {
    return communityCollection.where('members', arrayContains: uid).orderBy('lastActive', descending: true).snapshots();
  }

...

StreamBuilder(
            stream: DBService().userCommunities,
            builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
              if (snapshot.hasData)
                return ListView.builder(
                  itemCount: snapshot.data.documents.length,
                  itemBuilder: (context, index) {
                  return ListTile(title: Text(snapshot.data.documents[index]['name']));
                });
              else
                return Container();
            },
          ),

testCommunity2 在成员中不包含用户的 ID,但我的应用在列表视图中显示两个社区

【问题讨论】:

  • 添加你的数据库截图

标签: firebase flutter google-cloud-firestore


【解决方案1】:

修好了!我发现我的 uid 在 return communityCollection.where('members', arrayContains: uid) 中返回 null

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 2023-02-10
    • 2021-02-15
    • 1970-01-01
    相关资源
    最近更新 更多