Can someone help why this code return no message when it obvious that their a data in my message collection when i tried to get the last message to display in the widget below.
![message collection][1]
![1]: https://i.stack.imgur.com/uGJgV.png
final ChatMethods chatMethods = ChatMethods();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(
widthFactor: 5,
child: Text(
'Message',
style: mystyle(
20.0,
Style.Colors.titleColor,
),
),
),
),
body: StreamBuilder(
stream: chatMethods.fetchLastMessageBetween(
senderId: firebaseAuth.currentUser.uid, receiverId: widget.uid),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
var docList = snapshot.data.docs;
if (docList.isNotEmpty) {
Message message = Message.fromMap(docList.last.data());
return SizedBox(
width: MediaQuery.of(context).size.width * 0.6,
child: Text(
message.message,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
);
}
return Text(
"No Message",
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
);
}
return Text(
"..",
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
);
},
),
);
}
}