I’m new to Dart and Flutter. I have a list of strings which contains some paragraphs but I can’t figure out how to sort it based on how much it matches with a string given by the user.
I have tried this but it seems I dons not work
paras.sort((a, b) => b.contains(userPara).compareTo(a.contains(userPara));
2
Answers
That depends on how you define "how much it matches".
If we say like you want to sort them based on who has the highest amount of equal characters to your
match
descending, then you would do the following:The compare function should return a positive number if b is ordered before a and a negative number if a is ordered before b. Otherwise it should return 0.