Home > Net >  Flutter Firebase OrderBy() not outputting in alphabetical order
Flutter Firebase OrderBy() not outputting in alphabetical order

Time:02-01

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?

CodePudding user response:

Firebase OrderBy is case sensitive.

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

Cloud Firestore Case Insensitive Sorting Using Query

CodePudding user response:

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.

  •  Tags:  
  • Related