I\'m trying to sort a list by alphabetical order and tried porting something i had in javascript to flutter. But it gives me an exception on String that it does not have the
Thanks to Remi's answer, I extracted this as a Function.
typedef Sort = int Function(dynamic a, dynamic b);
typedef SortF = Sort Function(String sortField);
SortF alphabetic = (String sortField) => (a, b){
return a[sortField].toLowerCase().compareTo(b[sortField].toLowerCase());
};
SortF number = (String sortField) => (a, b) {
return a[sortField].compareTo(b[sortField]);
};
with this you can write.
list.sort(alphabetic('name')); //replace name with field name
list.sort(number('name')); //replace name with field name