Version.parse constructor Null safety

Version.parse(
  1. String text
)

Creates a new Version by parsing text.

Implementation

factory Version.parse(String text) {
  final match = completeVersion.firstMatch(text);
  if (match == null) {
    throw FormatException('Could not parse "$text".');
  }

  try {
    var major = int.parse(match[1]!);
    var minor = int.parse(match[2]!);
    var patch = int.parse(match[3]!);

    var preRelease = match[5];
    var build = match[8];

    return Version._(major, minor, patch, preRelease, build, text);
  } on FormatException {
    throw FormatException('Could not parse "$text".');
  }
}