0

I'm making a reddit clone in Flutter and using Cloud Firestore to store my data. I have a list of Communities that a user is following and want to show that in alphabetical order.

My current code is as follows:

class CommunitiesDatabase {
  // Read all
  static Stream<QuerySnapshot<Map<String, dynamic>>> readAllCommunities() {
    return FirebaseFirestore.instance
        .collection('Communities')
        .orderBy(
          'name',
          descending: true,
        )
        .snapshots();
  }
}

This is outputting the following list:

battlestations
assettocorsa
UKPersonalFinance
MapPorn
LifeProTips
Formula1

If I change the descending option to false it does reverse the order, but it still isn't alphabetical.

Can anyone help me understand why?

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
  • 1
    Please check this: https://stackoverflow.com/questions/48096063/cloud-firestore-case-insensitive-sorting-using-query – Paulo Belo Feb 01 '22 at 10:06

2 Answers2

1

Firebase OrderBy is case sensitive.

Please check this answer on how to implement case insensitive sorting:

Cloud Firestore Case Insensitive Sorting Using Query

Paulo Belo
  • 2,309
  • 18
  • 16
0

Results that start wilt lower case letters will always be displayed before the ones that start with a capital letter. That's not a rule that applies only in Dart but in all programming languages.

Can anyone help me understand why?

Why? Because it's about the List of Unicode characters.

You can also check:

The last one is for the Realtime Database but the same rules apply. You can save the lower case names as well.

Alex Mamo
  • 112,184
  • 14
  • 139
  • 167