validateExistingFlutterProject static method
Validates that projectDir points to a valid existing Flutter project directory.
Checks that pubspec.yaml exists and contains a flutter: key.
Implementation
static void validateExistingFlutterProject(Directory projectDir) {
if (!projectDir.existsSync()) {
throw ValidationException(
'This command must be run inside a Flutter project (directory "${projectDir.path}" does not exist).',
);
}
final pubspecFile = File('${projectDir.path}/pubspec.yaml');
if (!pubspecFile.existsSync()) {
throw const ValidationException(
'This command must be run inside a Flutter project (no pubspec.yaml found).',
);
}
final content = pubspecFile.readAsStringSync();
if (!content.contains('flutter:')) {
throw const ValidationException(
'This command must be run inside a Flutter project (pubspec.yaml does not contain a "flutter:" section).',
);
}
}