Open flowtoolz opened 1 year ago
Use this under stream builder stream: _firestore.collection("messages").orderBy('time',descending: false).snapshots(),
Use this under stream builder stream: _firestore.collection("messages").orderBy('time',descending: false).snapshots(),
When I do this, even tho I still get the data(print shows it), it doesnt appear on screen.
Any idea why? https://github.com/KatayR/chatty/blob/master/lib/screens/chat_screen.dart
Edit: Figured it out. I didn't create a "time" field in my documents at all... So I went to firebase and created another field called "time" which is a "timestamp". Now they sort as they should.
I also modified chat_screen.dart with "'text': messageText, 'sender': loggedInUser!.email, 'time': FieldValue.serverTimestamp()" so every text I sent also sends timestamp with it. Hope this helps someone in the future
It seems that the default order of documents in Firebase is by their ID instead of their creation date. So just reversing the order of messages doesn't do it (anymore). Maybe the messages need a third field with their creation date, so the client can then sort them by that date.
https://github.com/londonappbrewery/Flash-Chat-Flutter-Complete/blob/a4b44e20a5efe6ebe6a0dc42609a54906da6bf21/lib/screens/chat_screen.dart#L111