@@ -70,13 +70,17 @@ class Version implements VersionConstraint, VersionRange {
7070 /// This is split into a list of components, each of which may be either a
7171 /// string or a non-negative integer. It may also be empty, indicating that
7272 /// this version has no pre-release identifier.
73+ ///
74+ /// **Note:** The returned list shouldn't be modified.
7375 final List <Object > preRelease;
7476
7577 /// The build identifier: "foo" in "1.2.3+foo".
7678 ///
7779 /// This is split into a list of components, each of which may be either a
7880 /// string or a non-negative integer. It may also be empty, indicating that
7981 /// this version has no build identifier.
82+ ///
83+ /// **Note:** The returned list shouldn't be modified.
8084 final List <Object > build;
8185
8286 /// The original string representation of the version number.
@@ -96,8 +100,10 @@ class Version implements VersionConstraint, VersionRange {
96100
97101 Version ._(this .major, this .minor, this .patch, String ? preRelease,
98102 String ? build, this ._text)
99- : preRelease = preRelease == null ? < Object > [] : _splitParts (preRelease),
100- build = build == null ? [] : _splitParts (build) {
103+ : preRelease = preRelease == null || preRelease.isEmpty
104+ ? []
105+ : _splitParts (preRelease),
106+ build = build == null || build.isEmpty ? [] : _splitParts (build) {
101107 if (major < 0 ) throw ArgumentError ('Major version must be non-negative.' );
102108 if (minor < 0 ) throw ArgumentError ('Minor version must be non-negative.' );
103109 if (patch < 0 ) throw ArgumentError ('Patch version must be non-negative.' );
0 commit comments