Search code examples
sortingdartlocale

Locale-sensitive string sort in Dart


I need to sort a List<String>. Its elements might contain non-ASCII characters (think é, ž, Æ, ...). Is there a way to do this in Dart while being locale-aware?

Something like localeCompare in Javascript.

Some examples:

Czech (cs_CZ)

List<String> czechWords = ['čeština', 'cvrček', 'chleba',];

// expected after calling a localizedSort() or similar method

List<String> czechWordsSorted = ['cvrček', 'čeština', 'chleba',];

Solution

  • The Dart platform libraries do not currently have any locale-specific string sorting or comparison functionality.