update static method

Future<void> update([
  1. bool isGit = false,
  2. bool forceUpdate = false
])

Implementation

static Future<void> update(
    [bool isGit = false, bool forceUpdate = false]) async {
  isGit = FlutterTemplateCli.arguments.contains('--git');
  forceUpdate = FlutterTemplateCli.arguments.contains('-f');
  if (!isGit && !forceUpdate) {
    var versionInPubDev =
        await PubDevApi.getLatestVersionFromPackage('flutter_template_cli');

    var versionInstalled = await PubspecLock.getVersionCli(disableLog: true);

    if (versionInstalled == versionInPubDev) {
      return LogService.info(
          Translation(LocaleKeys.info_cli_last_version_already_installed.tr)
              .toString());
    }
  }

  LogService.info('Upgrading flutter_template_cli …');

  try {
    if (Platform.script.path.contains('flutter')) {
      if (isGit) {
        await run(
            'flutter pub global activate -sgit https://github.com/nEdAy/flutter_template_cli/',
            verbose: true);
      } else {
        await run('flutter pub global activate flutter_template_cli',
            verbose: true);
      }
    } else {
      if (isGit) {
        await run(
            'flutter pub global activate -sgit https://github.com/nEdAy/flutter_template_cli/',
            verbose: true);
      } else {
        await run('flutter pub global activate flutter_template_cli',
            verbose: true);
      }
    }
    return LogService.success(LocaleKeys.success_update_cli.tr);
  } on Exception catch (err) {
    LogService.info(err.toString());
    return LogService.error(LocaleKeys.error_update_cli.tr);
  }
}