run static method

Future<int> run(
  1. String argument, {
  2. bool showLog = false,
})

Runs a Flutter command and waits for completion.

This method executes a Flutter command and captures its output, returning the exit code when the command completes.

Parameters:

  • argument: The Flutter command arguments
  • showLog: Whether to show the command being executed

Returns: The exit code of the Flutter command

Example:

// Run Flutter analyze
final exitCode = await FlutterHelper.run('analyze');
if (exitCode == 0) {
  print('Analysis completed successfully');
} else {
  print('Analysis failed with exit code: $exitCode');
}

// Run Flutter pub get and show the command
await FlutterHelper.run('pub get', showLog: true);

Implementation

static Future<int> run(String argument, {bool showLog = false}) async {
  String command = '${getCommandFlutter()} $argument';
  if (showLog) printMessage(command);
  return command.start(
    showLog: false,
    progressOut: (line) =>
        printMessage(line.replaceAll(RegExp(r'[\s\n]+$'), '')),
    progressErr: (line) =>
        printerrMessage(line.replaceAll(RegExp(r'[\s\n]+$'), '')),
  );
}