copy method Null safety

Version copy(
  1. {int? major,
  2. int? minor,
  3. int? patch,
  4. String? preRelease,
  5. String? build,
  6. String? text}
)

Creates a copy of this version overriding the old values

Implementation

Version copy({
  int? major,
  int? minor,
  int? patch,
  String? preRelease,
  String? build,
  String? text,
}) {
  String? currentBuild = this.build.join().trim();
  if (currentBuild.isEmpty) {
    currentBuild = build;
  }

  String? currentPre = this.preRelease.join().trim();
  if (currentPre.isEmpty) {
    currentPre = preRelease;
  }

  return Version(
    major ?? this.major,
    minor ?? this.minor,
    patch ?? this.patch,
    pre: preRelease ?? currentPre,
    build: build ?? currentBuild,
  );
}