Skip to content
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

Firestore Document Order Seems to Have Changed #28

Open
flowtoolz opened this issue Mar 13, 2023 · 2 comments
Open

Firestore Document Order Seems to Have Changed #28

flowtoolz opened this issue Mar 13, 2023 · 2 comments

Comments

@flowtoolz
Copy link

flowtoolz commented Mar 13, 2023

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.

final messages = snapshot.data.documents.reversed;

@flowtoolz flowtoolz changed the title Firestore Documents Order Seems to Have Changed Firestore Document Order Seems to Have Changed Mar 14, 2023
@kuChetan
Copy link

Use this under stream builder stream: _firestore.collection("messages").orderBy('time',descending: false).snapshots(),

@KatayR
Copy link

KatayR commented May 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants