Sorting List of object

PHOTO EMBED

Mon Jun 15 2020 12:33:08 GMT+0000 (Coordinated Universal Time)

Saved by @pratik.gtm #dart

main() {
  List customers = [];
  customers.add(Customer('Jack', 23));
  customers.add(Customer('Adam', 27));
  customers.add(Customer('Katherin', 25));

  customers.sort((a, b) => a.age.compareTo(b.age));
  print('Sort by Age: ' + customers.toString());

  customers.sort((a, b) => a.name.compareTo(b.name));
  print('Sort by Name: ' + customers.toString());
}
content_copyCOPY