addDependencies static method

Future<bool> addDependencies(
  1. String package, {
  2. String? version,
  3. bool isDev = false,
  4. bool runPubGet = true,
})

Implementation

static Future<bool> addDependencies(String package,
    {String? version, bool isDev = false, bool runPubGet = true}) async {
  if (containsPackage(package)) {
    LogService.info(
        LocaleKeys.ask_package_already_installed.trArgs([package]),
        false,
        false);
    final menu = Menu(
      [
        LocaleKeys.options_yes.tr,
        LocaleKeys.options_no.tr,
      ],
    );
    final result = menu.choose();
    if (result.index != 0) {
      return false;
    }
  }

  String packageName = package;

  if (version != null && version.isNotEmpty) {
    packageName = '$package:$version';
  }

  if (isDev) {
    packageName = 'dev:$packageName';
  }

  await ShellUtils.addPackage(packageName);

  // version = version == null || version.isEmpty
  //     ? await PubDevApi.getLatestVersionFromPackage(package)
  //     : '^$version';
  // if (version == null) return false;
  // final dependency = HostedDependency(
  //   version: VersionConstraint.parse(version),
  // );

  // if (isDev) {
  //   pubSpec.devDependencies[package] = dependency;
  // } else {
  //   pubSpec.dependencies[package] = dependency;
  // }

  // _savePub(pubSpec);
  if (runPubGet) await ShellUtils.pubGet();
  LogService.success(LocaleKeys.sucess_package_installed.trArgs([package]));
  return true;
}