pathPubspecAddDependency function

Future<bool> pathPubspecAddDependency(
  1. String dir,
  2. String dependency, {
  3. List<String>? dependencyLines,
})

Returns true if added

Implementation

Future<bool> pathPubspecAddDependency(String dir, String dependency,
    {List<String>? dependencyLines}) async {
  var map = await pathGetPubspecYamlMap(dir);
  if (!pubspecYamlHasAnyDependencies(map, [dependency])) {
    var content = _loadPubspecContent(dir);
    content = pubspecStringAddDependency(content, dependency,
        dependencyLines: dependencyLines);
    await _writePubspecContent(dir, content);
    return true;
  }
  return false;
}