firebase / FirebaseUI-Flutter

Apache License 2.0
99 stars 86 forks source link

🐛 [firebase_ui_firestore] FirestoreListView won't refresh when using orderBy in query #29

Closed Nico04 closed 11 months ago

Nico04 commented 1 year ago

Bug report

When using FirestoreListView with an orderBy on the query, list won't refresh when a new entry is added to the database. As soon as I remove the orderBy on the query, it works as exoected.

Steps to reproduce

  1. Build a Firestore collection with several entries.
  2. Build a FirestoreListView widget with a query that uses orderBy :
    late final _messages = _db.collection('messages').withConverter<Message>(
    fromFirestore: (snapshot, _) => Message.fromJson(snapshot.id, snapshot.data()!),
    toFirestore: (model, _) => model.toJson(),
    );
    Query<Message> getMessagesQuery(String userId) => _messages.where('senderId', isEqualTo: userId).orderBy('sentAt');
  3. The widget will display the entries, as expected.
  4. Add a new entry to the database.
  5. The new item will not be displayed.

Expected behavior

If you do the same without the orderBy on the query, it works as expected, and display new entries in realtime.

Additional context

Using all latest stable packages version and stable Flutter.

Nico04 commented 1 year ago

EDIT : After some digging, I found out that with proper Firestore index created, it looks like it's working as expected 👍