I'd like to sort a list of countries in Dart, by localised country name. This is how I'm doing it:

final countryNames = CountryNames.of(context);
_countries.sort((a, b) => 
  (countryNames.data[a.isoCode.toUpperCase()] ?? "").compareTo(
    countryNames.data[b.isoCode.toUpperCase()] ?? ""));

I'm not worried about the countries that aren't found in countryNames.data -- I just filter those out of the displayed list. The problem is that in English,

Åland Islands

appears at the bottom of the forward-sorted list, and in French and other languages with a proliferation of special characters, the situation is even worse.

Is there an idiomatic way to sort strings in Dart so that special characters are treated more logically?

Solution 1: Ovidiu

You would have to create a mapping between regular characters and characters with diacritics, and use it within the comparison such that 'Åland Islands' is considered to be 'Aland Islands' for comparison purposes.

It looks like someone else has already done that and published it as a package: https://pub.dev/packages/diacritic