runDartOrFlutterCommand static method
Future
runDartOrFlutterCommand(
- String forDirectory, {
- List<
String> args = const [], - StdoutSession? stdoutSession,
runs the dart or flutter command with the given args
.
The decision which command to run is taken from the pubspeck.yaml file in
forDirectory
Implementation
static Future runDartOrFlutterCommand(
String forDirectory, {
List<String> args = const [],
StdoutSession? stdoutSession,
}) async {
final pubspecPath = path.join(forDirectory, 'pubspec.yaml');
final pubspecExists = await File(pubspecPath).exists();
if (!pubspecExists) {
throw RunDartError(
'Error running pub get in $forDirectory:\nThis is not a valid dart package directory');
}
final yamlContent = await File(pubspecPath).readAsString();
final pubSpec = Pubspec.parse(yamlContent);
if (!pubSpec.dependencies.containsKey('flutter')) {
return _runDartOrFlutterCommand(
_getDartExecutablePath(),
workingDirectory: forDirectory,
args: args,
stdoutSession: stdoutSession,
);
} else {
final flutterExecutablePath = await _findFlutterExecutablePath();
if (flutterExecutablePath == null) {
logWarning(
'Unable to find matching Flutter executable. Using system Flutter executable...',
extras: {
'dart executable': _getDartExecutablePath(),
},
);
}
return _runDartOrFlutterCommand(
flutterExecutablePath ?? 'flutter',
workingDirectory: forDirectory,
args: args,
stdoutSession: stdoutSession,
runInShell: flutterExecutablePath == null,
);
}
}