flutter function

int flutter(
  1. List<String> args, {
  2. Directory? workingDirectory,
  3. Progress? progress,
  4. bool nothrow = false,
  5. String throwOnError()?,
})

Executes Flutter command from Flutter SDK set in flutterSdk

Set nothrow to true to ignore errors when executing the flutter command. The exit code will still be non-zero if the command failed and the method will still throw if the Flutter SDK was not set in initializeSidekick

If throwOnError is given and the command returns a non-zero exit code, the result of throwOnError will be thrown regardless of nothrow

Implementation

int flutter(
  List<String> args, {
  Directory? workingDirectory,
  dcli.Progress? progress,
  bool nothrow = false,
  String Function()? throwOnError,
}) {
  final sdk = flutterSdk;
  if (sdk == null) {
    throw FlutterSdkNotSetException();
  }

  for (final initializer in _sdkInitializers) {
    final future = initializer(sdk);
    if (future is Future) {
      dcli.waitForEx(future);
    }
  }

  final process = dcli.startFromArgs(
    Platform.isWindows ? 'bash' : sdk.file('bin/flutter').path,
    [if (Platform.isWindows) sdk.file('bin/flutter.exe').path, ...args],
    workingDirectory: workingDirectory?.absolute.path,
    nothrow: nothrow || throwOnError != null,
    progress: progress,
    terminal: progress == null,
  );

  final exitCode = process.exitCode ?? -1;

  if (exitCode != 0 && throwOnError != null) {
    throw throwOnError();
  }

  return exitCode;
}