run method
Runs the project creation command.
Returns a ProjectConfig if creation succeeds, or null if cancelled.
The currentDir parameter specifies the directory where the project
will be created or detected.
Implementation
Future<ProjectConfig?> run(String currentDir) async {
Console.printBanner();
String projectDir = currentDir;
String projectName;
// Check if current directory is a Flutter project
if (FsUtils.isFlutterProjectRoot(currentDir)) {
final pubspec = File(p.join(currentDir, 'pubspec.yaml'));
final content = pubspec.readAsStringSync();
final nameMatch =
RegExp(r'^name:\s*(\S+)', multiLine: true).firstMatch(content);
projectName = nameMatch?.group(1) ?? p.basename(currentDir);
Console.success('Flutter project detected: $projectName');
} else {
Console.info('No Flutter project found in current directory.');
final name = Console.prompt('Enter project name (snake_case)');
if (name == null || name.isEmpty) {
Console.error('Project name cannot be empty.');
return null;
}
projectName = FsUtils.toSnakeCaseSafe(name);
projectDir = p.join(currentDir, projectName);
}
// Project type
final typeIndex = Console.selectFromList(
'📱 Select project type:',
['Application (app)', 'Package'],
);
final projectType = typeIndex == 0 ? ProjectType.app : ProjectType.package;
// Platform selection
final platformLabels = [
'Android',
'iOS',
'Web',
'Windows',
'macOS',
'Linux'
];
final platformValues = [
Platform.android,
Platform.ios,
Platform.web,
Platform.windows,
Platform.macos,
Platform.linux,
];
final platformIndices = Console.selectMultipleFromList(
'🖥️ Select target platforms:',
platformLabels,
);
final platforms = platformIndices.map((i) => platformValues[i]).toList();
// State management
final smIndex = Console.selectFromList(
'⚡ Select state management:',
['Provider', 'Riverpod', 'GetX', 'BLoC'],
);
final smValues = [
StateManagement.provider,
StateManagement.riverpod,
StateManagement.getx,
StateManagement.bloc,
];
final stateManagement = smValues[smIndex];
final config = ProjectConfig(
name: projectName,
type: projectType,
platforms: platforms,
stateManagement: stateManagement,
);
Console.separator();
Console.step('Creating Flutter project...');
await _scaffoldProject(config, projectDir, currentDir);
return config;
}