-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message sorting not working as intended. #1
Comments
After thinking this through a little bit before embarking on coding (just by looking at the order in which they appear in Firebase), it seems the real solution is to add a timestamp to each message, then on retrieval, sort the messages based on the timestamp before adding them to the |
can you share the code after your update @ak2766 |
I added timestamp into the code and it worked. @FadyWaheed11 |
I used DateTime into the code and it works well. |
Apologies, I got busy and haven't returned to this, but I see others had the same idea and already have a solution. Hopefully that works for you too. |
Thanks bro it works @ak2766 |
Hello guys, I know it's been a while but can I add something? With the method you proposed, if someone with a phone clock which is not accurate it will mess up the order, right? I know that will be rare but it's something we should think about. |
If use unix time instead of phone clock it works well. |
Use This Code after clearing your all old Database message and Data from firebase cloud DataBase . Once you clear all the previous data from database, you can you this code . `import 'package:flutter/material.dart'; final _firestore = Firestore.instance; class ChatScreen extends StatefulWidget { class _ChatScreenState extends State { String messageText; @OverRide
} void getCurrentUser() async { @OverRide class MessagesStream extends StatelessWidget {
} class MessageBubble extends StatelessWidget { final String sender; @OverRide |
very good,Thanks |
TimeStamp or DateTime is not proper method to sorting messages because i give one example, So there are two Devices, DeviceA and DeviceB both install this App but DeviceA's time is 10:45 and DeviceB's time is 10:50 so messages not sorting properly, my suggestion is to use this below method to work properly... onPressed: () {
class MessagesStream extends StatelessWidget { ( _firestore |
@RahiPatel25 Thank you. This fixed the sorting issue as well as an issue with messages grouping together out of order, AND by the sender. For the sake of making your comment a little easier to read I will include the code that worked for me below... The two major components being:
and
In your chat_screen.dart file...
|
I even could not open, when I run code, and tried to open on my phone it stoppes doesnt open why this could be? |
Flutter has changed many things over the past few years along with class names and different objects. Use this code to sort the most recent messages final _fireStore = FirebaseFirestore.instance; class ChatScreen extends StatefulWidget { @OverRide class _ChatScreenState extends State { String messageText; @OverRide void getCurrentUser() async { void messagesStream() async { @OverRide class MessagesStream extends StatelessWidget { @OverRide class MessageBubble extends StatelessWidget { |
Hey I'm working on an almost same app, the order is still very unpredictable even with those two reverse conditions. |
Great , it works ,and me also Thanks guys |
Just wanted to state that my final chat_screen code is exactly identical to your final project but the sorting of messages isn't working as intended - both on the emulator and on my Galaxy S8+. See screenshots below. There's something very odd happening here.
Will try and fix it on my own and report back here.
I've included a number (1-8) either at the beginning or at the end of the chat message to allow you to follow message post chronology.
Emulator:
Galaxy S8:
The text was updated successfully, but these errors were encountered: