comparator method
Returns a negative number if value1
is less than value2
, zero if they are
equal, and a positive number if value1
is greater than value2
.
Almost the same: value1 - value2
Implementation
@override
int comparator(T value1, T value2) {
// If K <: Comparable, then we can just use Comparable.compare
// with no casts.
Object compare = Comparable.compare;
if (compare is Comparator<T>) {
return compare(value1, value2);
}
// Otherwise wrap and cast the arguments on each call.
return Comparable.compare(
value1 as Comparable<dynamic>, value2 as Comparable<dynamic>);
}