VersionRange constructor

VersionRange({
  1. Version? min,
  2. Version? max,
  3. bool includeMin = false,
  4. bool includeMax = false,
  5. bool alwaysIncludeMaxPreRelease = false,
})

Creates a new version range from min to max, either inclusive or exclusive.

If it is an error if min is greater than max.

Either max or min may be omitted to not clamp the range at that end. If both are omitted, the range allows all versions.

If includeMin is true, then the minimum end of the range is inclusive. Likewise, passing includeMax as true makes the upper end inclusive.

If alwaysIncludeMaxPreRelease is true, this will always include pre-release versions of an exclusive max. Otherwise, it will use the default behavior for pre-release versions of max.

Implementation

factory VersionRange(
    {Version? min,
    Version? max,
    bool includeMin = false,
    bool includeMax = false,
    bool alwaysIncludeMaxPreRelease = false}) {
  if (min != null && max != null && min > max) {
    throw ArgumentError(
        'Minimum version ("$min") must be less than maximum ("$max").');
  }

  if (!alwaysIncludeMaxPreRelease &&
      !includeMax &&
      max != null &&
      !max.isPreRelease &&
      max.build.isEmpty &&
      (min == null ||
          !min.isPreRelease ||
          !equalsWithoutPreRelease(min, max))) {
    max = max.firstPreRelease;
  }

  return VersionRange._(min, max, includeMin, includeMax);
}