0

I would like to sort hungarian String textes in a list, but i ran into a problem with accent characters.

For example:

final textList = ["Bb", "Aa", "Áa"];

textList.sort((a, b) => a.compareTo(b));

Output: ["Aa", "Bb", "Áa"]

But the current output have to be this: ["Aa", "Áa", "Bb"].

How can i solve this problem?

Péter
  • 273
  • 1
  • 10
  • 1
    Take a look at this: https://stackoverflow.com/questions/55986738/how-can-i-sort-a-list-of-strings-with-german-umlauts-in-dart – Er1 Nov 08 '21 at 16:57
  • not nice solutions... In fact, half of them are really bad solution. Flutter not handle culture during sort? – Péter Nov 08 '21 at 18:41
  • https://pub.dev/packages/diacritic might be the best solution for you for now. Flutter (Dart) does not have any string sorting based on culture, as far as I know. Sorting is usually done by ASCII code or Unicode. – Er1 Nov 09 '21 at 08:22
  • Unfortunatelly Diacritic package not solve my problem because it only change accent characters to non-accent characters and "E" and "É" will be equal. – Péter Nov 09 '21 at 12:53
  • You can use it like shown in this answer: https://stackoverflow.com/a/65736263/6704033 It should do what you want it to do. – Er1 Nov 09 '21 at 13:05
  • diacritic is not a solution for me. It just replace accent characters to non-accent in sort process. It does not make difference between “e” and “é” – Péter Nov 10 '21 at 14:28

0 Answers0