Skip to content

Instantly share code, notes, and snippets.

@jorwan
Last active December 31, 2023 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorwan/3d9f72b4d7b20bd51f97fff179865fa6 to your computer and use it in GitHub Desktop.
Save jorwan/3d9f72b4d7b20bd51f97fff179865fa6 to your computer and use it in GitHub Desktop.
sort list with nulls at the end in dart
void main() {
print("Current list");
var l = [1,5,2,null,0];
print(l);
print("Sorted List");
l.sort((a, b) {
int result;
if (a == null) {
result = 1;
} else if (b == null) {
result = -1;
} else {
// Ascending Order
result = a.compareTo(b);
}
return result;
});
print(l);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment