jampez77
jampez77

Reputation: 5241

Dart Firebase, unable to sort list using orderByValue

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

Upvotes: 0

Views: 556

Answers (1)

Hadrien Lejard
Hadrien Lejard

Reputation: 5924

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

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

Upvotes: 1

Related Questions