Cant figure out how to do it.
I'm using sort() with compareTo() to sort a list ascending by one criteria, but i need to resort it with a second criteria, keeping odd numbers in the beggining of the list.
widget.tasks.sort((a,b){
return a.key.compareTo(b.key);
});
This code above just sorts one of the attributes of the list. A need to sort a second one of integer numbers.
Here is working Example Copy code and run
List numlist = [1, 2, 3, 4, 5, 6, 7, 9, 10];
List oddList = [];
List evenList = [];
List firstOddThenEven = [];
for (final i in numlist) {
if (i.isEven) {
evenList.add(i);
} else if (i.isOdd) {
oddList.add(i);
}
}
firstOddThenEven.addAll(oddList);
firstOddThenEven.addAll(evenList);
print(firstOddThenEven);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With