primary method Null safety

Version primary(
  1. List<Version> versions

Returns the primary version out of versions.

This is the highest-numbered stable (non-prerelease) version. If there are no stable versions, it's just the highest-numbered version.

If versions is empty, throws a StateError.


static Version primary(List<Version> versions) {
  var primary = versions.first;
  for (var version in versions.skip(1)) {
    if ((!version.isPreRelease && primary.isPreRelease) ||
        (version.isPreRelease == primary.isPreRelease && version > primary)) {
      primary = version;
  return primary;