I have a list of maps in dart that I would like to sort.
The list I use:
List<myModel> myList;
(with maps inside):
(I created a model called 'myModel', so if I want to get the views: so I can use: myList[index].views to get the views of a map).
I tried this code:
setState(() {
filteredList = SplayTreeMap.from(
myList,
(a, b) => int.parse(myList[a].views)
.compareTo(int.parse(myList[b].views)));
});
(I want to sort the views, hight to low).
But I get this error:
error: A value of type 'SplayTreeMap' can't be assigned to a variable of type 'List<myModel>'.
What am I doing wrong?
Thanks in advance!
EDIT:
I 'query' my list this way.
filteredList = myList
.where((snapshot) => snapshot.views > 0)
.toList();
This works...
Is there a possibility to sort that way?