sortBy<R> method

void sortBy<R>(
  1. Comparable<R>? by(
    1. T item
    ), {
  2. bool ascending = true,
})

Sorts the list based on the comparable returned by by. By default the sorting is ascending

Implementation

void sortBy<R>(Comparable<R>? by(T item), {bool ascending = true}) {
  sort((a, b) {
    final byA = by(a);
    final byB = by(b);
    if (byA == null) return ascending ? -1 : 1;
    if (byB == null) return ascending ? 1 : -1;
    return _compareValues(byA, byB, ascending);
  });
}