resolveVersion function

Version resolveVersion({
  1. required Version? pubspecVersion,
  2. required String? appVersion,
  3. required String? buildVersion,
  4. required String? buildPreRelease,
  5. required String? buildMetadata,
})

Implementation

Version resolveVersion({
  required Version? pubspecVersion,
  required String? appVersion,
  required String? buildVersion,
  required String? buildPreRelease,
  required String? buildMetadata,
}) {
  Version version;
  if ((appVersion == null || appVersion.isEmpty) &&
      (buildVersion == null || buildVersion.isEmpty)) {
    version = pubspecVersion ?? Version(0, 0, 1);
  } else if (buildVersion != null && buildVersion.isNotEmpty) {
    version = Version.parse(buildVersion);
  } else {
    version = Version.parse(appVersion!.replaceFirst('v', ''));
  }

  if (buildPreRelease != null) {
    version = version.copyWith(pre: buildPreRelease);
  }

  if (buildMetadata != null) {
    version = version.copyWith(build: buildMetadata);
  }
  return version;
}