sortBy2<R, V> method

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

Sorts the list by comparing first comparing using by and if the items are equal, by comparing them using by2. By default the sorting is ascending

Implementation

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

    final byA2 = by2(a);
    final byB2 = by2(b);
    if (byA2 == null && byB2 == null) return 0;
    if (byA2 == null) return ascending ? -1 : 1;
    if (byB2 == null) return ascending ? 1 : -1;
    return _compareValues(byA2, byB2, ascending);
  });
}