I took a look at some similar questions but I didn't find what I'm looking for.
I have a StreamBuilder
whose snapshot has no data but if I look inside the collection that it's listening I can see that there are 2 documents.
This is my first time using StreamBuilder
so maybe I'm missing some basics rules.
I say that it has no data
because it's always displayed "No chats here"
.
This is the code (stream function later) :
StreamBuilder<ChatCard>(
stream: widget.database.streamChats(widget.user),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Container(
child: Text(
"There's something here!",
style: TextStyle(
color: Colors.white,
),
),
);
} else {
return Container(
child: Text(
"No chats here",
style: TextStyle(
color: Colors.white,
),
),
);
}
},
),
This is the stream function, there are some extra checks because I'm trying to figure it out what isn't working, by the way seems no error in try
block and no if
statements violated:
Stream<ChatCard> streamChats(MyUser sender) {
if (sender != null) {
if (sender.id != null) {
try {
FirebaseFirestore.instance
.collection("ids/tabs/${sender[0].toLowerCase()}/${sender.toLowerCase()}/chats")
.snapshots();
print(
"ids/tabs/${sender[0].toLowerCase()}/${sender.toLowerCase()}/chats'");
} on FirebaseException catch (e) {
print(e);
} catch (e) {
print(e);
}
} else
print("Sender ID null");
} else
print("Sender null");
}
If you can also provide me some informations about StreamBuilder
and Stream
in general, I would be very happy to listen but obviously this is a plus.
Solved, the problem was the Stream, I wasn't returning the right one but with QuerySnapshot
it works :
Stream<QuerySnapshot> streamChats(User sender) {
return FirebaseFirestore.instance
.collection("ids")
.doc("tabs")
.collection(sender.id[0].toLowerCase())
.doc(sender.id[0].toLowerCase())
.collection("chats")
.snapshots();
}