I have a list of maps, and i want to sort it based on values that are in another list, here is the data list:
final data = [{
'id' : 1,
},
{
'id' : 10,
},
{
'id' : 2,
},
{
'id' : 1,
},
{
'id' : 10,
},
{
'id' : 1000,
}];
And this is the sorting list:
List<int> sortingList = [1000,1, 6, 99];
I want to sort the data list based on the order of the ids that exists in the sortingList, meaning for example 1000 is in position one so i want the data that has id == 1000 at the beginning of the list, 1 is the second element of the sortingList so i want all the data that has id == 1 to be listed after the elements that has 1000 and so on. The elements that has id that's not in sortingList should be at the end of the list, the final result if i print the value id after sorting it should be like this:
for (var i = 0; i < data.length; i++) {
print(data[i]["id"]);
}
1000
1
1
10
2
10