I'm trying to build a page in Flutter that shows all the comments made by a user. For some reason, this stream builder loads the data, flashes it briefly, then acts as if there is no data. I'm sure it has something to do with the way my query/stream is built. Thanks for any help! Update I've discovered it is when I use the ".where" query that causes the problem.
This works great: FirebaseFirestore.instance.collectionGroup('comments').snapshots()
This loads correctly for about half a second then has no data: FirebaseFirestore.instance.collectionGroup('comments').where('uid', equalTo: uid).snapshots()
Code:
child: StreamBuilder<QuerySnapshot>(
builder: (context, snapshot) {
if (snapshot.hasData) {
List<CommentCard> commentList = [];
final comments = snapshot.data!.docs;
for (var comment in comments) {
commentList.add(CommentCard(
comment: Comment.fromSnapshot(
comment, comment.reference.parent.parent!.id)));
}
commentList.sort();
return Column(children: commentList);
}
return const Text("You have made no comments");
},
stream: FirebaseFirestore.instance
.collectionGroup('comments')
.where('uid', isEqualTo: currentUser.uid)
.snapshots(),
),