When you call snap.data.snapshot.value;
the data in the snapshot (which is ordered) is converted to a Map<String, Object>
which isn't ordered. To maintain the order, you'll want to listen to onChild...
instead.
Note that FlutterFire has a convenient firebase_list library that handles most of the heavy lifting of onChild...
for you.
Also see:
- Flutter Firebase Database wrong timestamp order
- Flutter sort Firebase snapshot by timestamp
- Flutter: Firebase Real-Time database orderByChild has no impact on query result