I am having trouble sorting data after a Firebase query. In my database, there is a collection of bikes, and each bike has a condition: Excellent, Great, Good, Fair, Poor, or Totaled. I would like to sort by condition so the start of the list is Excellent and the bottom is Totaled. I am then putting this in a ListView.
My Firebase structure: My Firebase structure
My query: FirebaseFirestore.instance.collection('bikes').snapshots();
I tried following this post's guidance, but to no avail. My very simple test below to sort by title length doesn't seem to sort anything (I'm passing the sorting to a function since sorting is only when the user clicks a button).
AsyncSnapshot<QuerySnapshot<Object?>> sortSnapshot(
AsyncSnapshot<QuerySnapshot<Object?>> snapshot) {
if (sortList == true) {
snapshot.data!.docs.sort((a, b) => a['Name'].length.compareTo(b['Name'].length));
}
return snapshot;
}