I have a stream that fetches data from my Firestore database and orders them according to the latest message. The problem is that the stream does not order them correctly. So basically it fetches the data once, and if I add a new message, it is not shown on top. Any idea why?
Here is my query: The Stream:
Stream<List<RoomsListModel>>? chats;
The query:
@override
void initState() {
chats = FirebaseFirestore.instance
.collection("rooms")
.where("users", arrayContains: userId)
.where("latestMessage", isNull: false)
.orderBy("latestMessage")
.orderBy("latestMessageTime", descending: true)
.snapshots()
.asyncMap((events) =>
Future.wait([for (var event in events.docs) generateRoom(event)]));
super.initState();
}