installPackageToCache static method
Future<String>
installPackageToCache(
- String packageName,
- String? version, {
- StdoutSession? stdoutSession,
installs a package to the pub cache and returns the path to it throws RunDartError on failure
if no version
is provided dart will decide what version to use ("the best of all known versions")
Implementation
static Future<String> installPackageToCache(
String packageName,
String? version, {
StdoutSession? stdoutSession,
}) async {
await DartInteraction.runDartCommand(
args: [
'pub',
'cache',
'add',
packageName,
if (version != null) '-v $version',
],
stdoutSession: stdoutSession,
);
if (version == null) {
await stdoutSession?.writeln(
'No version for $packageName specified, using latest version');
final latestVersion = getLatestVersionInCacheFor(packageName);
version = latestVersion.toString();
await stdoutSession?.writeln('Using version $version');
}
return getPackagePathInCache(packageName, version);
}