Last active
July 16, 2020 18:34
-
-
Save aya-eiya/58e8e60aec45dfaf63272b6afdcc2cfd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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