compareTo method

  1. @override
int compareTo(
  1. covariant Product other
)
override

The order of the comparisons is:

  1. name
  2. cost

The two currencies must be the same.

Implementation

@override
int compareTo(covariant Product other) {
  // 1ยบ comparison
  final int comparison1 = name.compareTo(other.name);
  if (comparison1 != 0) return comparison1;

  // Last comparison
  final int comparison2 = cost.compareTo(other.cost);
  return comparison2;
}