ComparableVersion constructor

ComparableVersion(
  1. String version
)

Creates a ComparableVersion by parsing version.

The version string must be in major.minor.patch format where all three components are non-negative integers.

Throws FormatException if version does not have exactly three dot-separated integer parts.

Implementation

factory ComparableVersion(String version) {
  final parts = version.split('.');
  if (parts.length != 3) {
    throw FormatException('Invalid version string: $version');
  }
  final nums = <int>[];
  for (final part in parts) {
    final n = int.tryParse(part);
    if (n == null) {
      throw FormatException('Invalid version string: $version');
    }
    nums.add(n);
  }
  return ComparableVersion._(version, nums[0], nums[1], nums[2]);
}