checkIfFlutterExistsIfSoCreate function

void checkIfFlutterExistsIfSoCreate(
  1. String projectName
)

Implementation

void checkIfFlutterExistsIfSoCreate(String projectName) {
  print('Current working directory: ${Directory.current.path}');

  // Verify flutter command exists
  final flutterCheck = Process.runSync('where', ['flutter'], runInShell: true);
  if (flutterCheck.exitCode != 0 || flutterCheck.stdout.isEmpty) {
    print('Error: flutter command not found in PATH.');
    print(
      'Ensure Flutter SDK is installed and added to PATH (e.g., C:\\flutter\\bin).',
    );
    exit(1);
  }
  print('Flutter command found: ${flutterCheck.stdout}');

  // Run flutter create
  final flutterCreateResult = Process.runSync(
    'flutter',
    ['create', projectName],
    workingDirectory: Directory.current.path,
    runInShell: true, // Ensure shell environment on Windows
  );

  if (flutterCreateResult.exitCode != 0) {
    print('Error running flutter create: ${flutterCreateResult.stderr}');
    exit(1);
  }

  print('Flutter project $projectName created.');
}