Flutter Firebase无法返回正确的查询文档

时间:2020-07-05 08:35:10

标签: firebase flutter google-cloud-firestore

Screenshot of my database我想在“社区”集合中找到所有文档,其中用户ID包含在“成员”数组中。 但是我的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,但是我的应用在列表视图中显示了两个社区

1 个答案:

答案 0 :(得分:0)

解决了!我发现我的uid在return communityCollection.where('members', arrayContains: uid)

中返回null