From c5942ea346b2c8fdda3f2d7eb9fa8d92824e0b6b Mon Sep 17 00:00:00 2001 From: Luke Aguilar Date: Mon, 6 May 2024 11:49:50 +1000 Subject: [PATCH] Added parseNullable --- lib/version.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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");