runClean function

Future<void> runClean({
  1. bool cleanCache = false,
})

Cleans Flutter build artifacts (and optionally Dart pub cache).

Use runClean for direct clean; use runCleanInteractive to let the user choose between Flutter-only clean or Flutter + pub cache clean.

Implementation

Future<void> runClean({bool cleanCache = false}) async {
  if (!FlutterProjectDetector.hasPubspec) {
    ConsoleLog.error('No pubspec.yaml found. Run from project root.');
    return;
  }

  ConsoleLog.title('Cleaning Flutter project...');
  final code = await ProcessRunner.runFlutter(['clean']);
  if (code != 0) {
    ConsoleLog.error('Flutter clean failed with exit code $code');
    return;
  }
  ConsoleLog.success('Flutter clean completed.');

  if (cleanCache) {
    ConsoleLog.step('Cleaning Dart pub cache...');
    final cacheCode = await ProcessRunner.runDart(['pub', 'cache', 'clean']);
    if (cacheCode == 0) {
      ConsoleLog.success('Pub cache cleaned.');
    } else {
      ConsoleLog.warning('Pub cache clean exited with code $cacheCode');
    }
  }
}