Created with <3 with dartpad.dev.
Last active
October 13, 2022 03:23
-
-
Save kenyk7/dadecd4dd5100fbc1fbe72d6a4a1e8ed to your computer and use it in GitHub Desktop.
Dart order list object by property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Category { | |
const Category({ | |
required this.name, | |
}); | |
final String name; | |
} | |
List<Category> categories = [ | |
const Category(name: 'cat3'), | |
const Category(name: 'cat1'), | |
const Category(name: 'cat2'), | |
]; | |
void main() { | |
categories.sort((a, b) => a.name.compareTo(b.name)); | |
// print result | |
for (final category in categories) { | |
print(category.name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment