I\'m trying to sort snapshot by timestamp but returns original order.
data structure looks like this
I have two snapshot and timestamps are -153602546653
Unfortunately when you call snapshot.data?.snapshot?.value
, the resulting Map
doesn't have space for the order of the items anymore.
In most Firebase SDKs you can solve this by looping over the children of the snapshot in the value event listener. But in Flutter you will need to listen to onChildAdded
events to maintain the value of the items in Flutter, at least until this issue is addressed: https://github.com/flutter/flutter/issues/20745.
From one of my own projects:
ref.orderByKey().equalTo("child1").onChildAdded.listen((event) {
print(event.snapshot.key);
});
ref.child("child1").once().then((snapshot) {
print("Done loading all data for child1");
});
This will first print the keys of all child nodes (in the requested order), and then "Done loading all data for child1"
.