diff --git a/lib/version.dart b/lib/version.dart index 51199af..5d03dfe 100644 --- a/lib/version.dart +++ b/lib/version.dart @@ -188,6 +188,18 @@ class Version implements Comparable { build: build, preRelease: preReleaseList); } + /// Creates a nullable [Version] instance from a string. + /// + /// The string must conform to the specification at http://semver.org/ + /// Returns null if the string is empty or null + /// Throws [FormatException] if the string does not conform to the spec. + static Version? parseNullable(String? versionString) { + if (versionString == null || versionString.isEmpty) { + return null; + } + return parse(versionString); + } + static int _compare(Version? a, Version? b) { if (a == null) { throw ArgumentError.notNull("a");