updateVersion static method

void updateVersion(
  1. String newVersionName,
  2. String? newBuildNumber
)

Updates the version in the pubspec.yaml file. @param {String} newVersionName The new version name (e.g., "1.0.1"). @param {String?} newBuildNumber The new build number, or null to keep existing.

Implementation

static void updateVersion(String newVersionName, String? newBuildNumber) {
  var pubspecContent = FileService.getPubspecContent();
  if (pubspecContent == null) return;

  final newVersionString =
      'version: $newVersionName${newBuildNumber != null ? '+$newBuildNumber' : ''}';
  final updatedContent = pubspecContent.content.replaceFirst(
    _versionPattern,
    newVersionString,
  );

  FileService.writePubspecContent(
    updatedContent,
    newVersionName,
    newBuildNumber,
  );
}