I am trying to query my Firebase database.
I wrote the following code to pull the list of groups where a specific user is a member. The code is appended below. When I run the code, it returns nothing. I tried to query directly using query builder in the console, however, it does not work there either.
I have been at this for sometime but cannot seem to find the issue. Can someone help me out?
Widget _buildGroupsList() {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('groups')
.where(
'members',
arrayContainsAny: [
{'id': user.uid}
],
)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return const Center(child: Text('Something went wrong'));
}
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
final List<Widget> groupCards = [];
for (var doc in snapshot.data!.docs) {
Map<String, dynamic> groupData = doc.data() as Map<String, dynamic>;
groupCards.add(_buildGroupCard(groupData));
}
return ListView(
children: groupCards,
);
},
);
}
I built the query in the console and it did not return the data either. It did not throw and error. It just did not return anything.
Serges Lemo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1