I have a Flutter app that shows a list of dates from a Firebase realtime database. I'm trying to 'flip' the order which they are shown.

Here is what i'm trying to do in Dart at the moment:

final FirebaseDatabase database = FirebaseDatabase.instance;
database.setPersistenceEnabled(true);

itemRef = database.reference().child('dings');
itemRef.orderByValue();
itemRef.keepSynced(true);
itemRef.onChildAdded.listen(_onEntryAdded);

I've also tried to change the Firebase rules as a method of sorting as follows:

"dings": {
  ".indexOn": ".value",
  "$ding": {
    ".write": "!data.exists()"
  }
}

Neither of these method have any effect on the order of the list. Any help is always appreciated. Thanks.

Here is the list as it is: Firebase List


Solution 1: Hadrien Lejard

itemRef.orderByValue(); return a Query object that you can use directly.

itemRef.orderByValue().onChildAdded.listen(_onEntryAdded)