I have a list (in flutter):
loadedSummaryList = [
'BILD',
'DRIT',
'VIMN',
'WELT',
'FLUTTER',
'ALL'
];
, and I want to sort this list like:
['WELT', 'BILD', 'VIMN', 'DRIT', 'ALL', 'FLUTTER']
in other words, I want to sort the first four elements of the list always like 'WELT', 'BILD', 'VIMN', 'DRIT', and then alphabetically. I tried it like this:
List<String> sortList = ['WELT', 'BILD', 'VIMN', 'DRIT'];
loadedSummaryList.sort(
(a, b) {
int aIntex = sortList.indexOf(a.name);
int bIntex = sortList.indexOf(b.name);
return aIntex.compareTo(bIntex);
},
);
which returns
['ALL', 'FLUTTER', 'WELT', 'BILD', 'VIMN', 'DRIT'];
but actually, I want to have it like:
['WELT', 'BILD', 'VIMN', 'DRIT', 'ALL', 'FLUTTER']
could someone help me, please? thanks in advance