ensureDependency method
Ensures that package exists in the project's dependencies.
Adds the dependency using the specified version if it is not already
present. When ensureLoaded is true, the pubspec is loaded before
checking the dependencies.
Implementation
Future<void> ensureDependency(
String package, {
String version = 'any',
bool ensureLoaded = false,
}) async {
if (ensureLoaded) await _ensureLoaded();
final dependencies = _dependencies();
if (dependencies.containsKey(package)) return;
await _set(['dependencies', package], version);
LoggerService.success('Added dependency: $package');
}