dart function

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

Executes the dart cli associated with the project via flutterw https://github.com/passsy/flutter_wrapper

Makes sure flutterw is executed beforehand to download the dart-sdk

Set nothrow to true to ignore errors when executing the dart command. The exit code will still be non-zero if the command failed and the method will still throw if the Dart 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 dart(
  List<String> args, {
  Directory? workingDirectory,
  dcli.Progress? progress,
  bool nothrow = false,
  String Function()? throwOnError,
}) {
  Directory? sdk = dartSdk;
  if (sdk == null) {
    if (flutterSdk != null) {
      final embeddedSdk = flutterSdk!.directory('bin/cache/dart-sdk');
      if (!embeddedSdk.existsSync()) {
        // Flutter SDK is not fully initialized, the Dart SDK not yet downloaded
        // Execute flutter_tool to download the embedded dart runtime
        flutter([], workingDirectory: workingDirectory, nothrow: true);
      }
      if (embeddedSdk.existsSync()) {
        sdk = embeddedSdk;
      }
    }
  }
  if (sdk == null) {
    throw DartSdkNotSetException();
  }

  final dart =
      Platform.isWindows ? sdk.file('bin/dart.exe') : sdk.file('bin/dart');

  final process = dcli.startFromArgs(
    dart.path,
    args,
    workingDirectory: workingDirectory?.path,
    progress: progress,
    nothrow: nothrow || throwOnError != null,
    terminal: progress == null,
  );

  final exitCode = process.exitCode ?? -1;

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

  return exitCode;
}