Skip to content

Instantly share code, notes, and snippets.

@aya-eiya
Last active July 16, 2020 18:34
Show Gist options
  • Save aya-eiya/58e8e60aec45dfaf63272b6afdcc2cfd to your computer and use it in GitHub Desktop.
Save aya-eiya/58e8e60aec45dfaf63272b6afdcc2cfd to your computer and use it in GitHub Desktop.
void main() {
final list1 = [
const Fruits(id: 1, order: 2, name: '🍌'),
const Fruits(id: 2, order: 1, name: '🍎'),
const Fruits(id: 3, order: 3, name: '🍊'),
];
list1..sort();
print(list1);
}
class Fruits implements Comparable<Fruits> {
const Fruits({this.id,int order,this.name}):order = order ?? 0;
final int id;
final int order;
final String name;
@override
int compareTo(Fruits other) => order.compareTo(other?.order);
@override
String toString() => 'Fruits(id:$id,order:$order,name:$name)';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment