updateVersionCode function

Future<bool> updateVersionCode()

Implementation

Future<bool> updateVersionCode() async {
  var version = await getAttributeValue('version') as String?;
  if (version == null) {
    logger.e('Failed to get attribute: version');
    return false;
  }
  final versionCode = await gitCommitCount();
  if (version.contains('+')) {
    version = version.substring(0, version.indexOf("+"));
  }
  version += '+$versionCode';

  final yamlFile = await getYamlFile();
  if (yamlFile == null) return false;
  final yamlFileContent = yamlFile.readAsLinesSync();
  final attribute = 'version: ';
  final index = yamlFileContent.indexWhere((element) => element.startsWith(attribute));
  yamlFileContent.replaceRange(index, index + 1, ['$attribute$version']);
  await writeFile(yamlFile, yamlFileContent);
  return true;
}