assignVersionWeight function

String assignVersionWeight(
  1. String version
)

Converts Flutter versions and channels to comparable semver strings. Assigns weights: git commits (500.0.0), master (400.0.0), stable (300.0.0), beta (200.0.0), dev (100.0.0), invalid (0.0.0).

Implementation

String assignVersionWeight(String version) {
  /// Assign version number to continue to work with semver
  if (isPossibleGitCommit(version)) {
    version = '500.0.0';
  } else {
    switch (version) {
      case 'master':
        version = '400.0.0';
        break;
      case 'stable':
        version = '300.0.0';
        break;
      case 'beta':
        version = '200.0.0';
        break;
      case 'dev':
        version = '100.0.0';
        break;
      default:
    }
  }

  if (version.contains('v')) {
    version = version.replaceFirst('v', '');
  }

  bool isCustom = version.contains('custom_');

  if (isCustom) {
    version = version.replaceFirst('custom_', '');
  }

  try {
    // Validate version format - throws if invalid
    final _ = Version.parse(version);
  } on Exception {
    if (isCustom) {
      return '400.0.0';
    }

    return '0.0.0';
  }

  return version;
}