sortedBy<K extends Comparable<Object?>> method

List<T> sortedBy<K extends Comparable<Object?>>(
  1. K key(
    1. T item
    ), {
  2. bool descending = false,
})

New list sorted by a field; descending reverses it. users.sortedBy((u) => u.name)

Implementation

List<T> sortedBy<K extends Comparable<Object?>>(K Function(T item) key, {bool descending = false}) => toList()..sort((T a, T b) => descending ? key(b).compareTo(key(a)) : key(a).compareTo(key(b)));