antiprioritize method Null safety

int antiprioritize(
  1. Version a,
  2. Version b
)

Like prioritize, but lower version numbers are considered greater than higher version numbers.

This still considers prerelease versions to be lower than non-prerelease versions. Pub uses this when downgrading -- it chooses the lowest version but still excludes pre-release versions when possible.

Implementation

static int antiprioritize(Version a, Version b) {
  if (a.isPreRelease && !b.isPreRelease) return -1;
  if (!a.isPreRelease && b.isPreRelease) return 1;

  return b.compareTo(a);
}