getHighestMatchesFromMatches function

List<PercentageMatch> getHighestMatchesFromMatches (
  1. List<PercentageMatch> matches
)

Returns the matches with the highest PercentageMatch.percentage.

If there are multiple PercentageMatches with the same PercentageMatch.percentage, there will be more than one item in the List returned. null will be returned if matches is empty.

Implementation

List<PercentageMatch> getHighestMatchesFromMatches(
    List<PercentageMatch> matches) {
  if (matches.isEmpty) {
    return null;
  }

  matches
      .sort((first, second) => first.percentage.compareTo(second.percentage));
  return matches
    ..retainWhere((match) => match.percentage == matches.last.percentage);
}