startInteractive method
void
startInteractive()
Default interactive mode
Implementation
void startInteractive() {
print('🚀 Flutter API Model Generator');
print('-----------------------------------------');
// Menu
print('\nWhat do you want to do?');
print('1. Generate Model');
print('2. Generate Model + Service');
print('3. Generate Model + Service + Repository');
print('4. Generate API Client (from config)');
print('5. Batch Generate from Folder');
print('6. Sync Existing Models');
stdout.write('Choice (1-6, default: 1): ');
String? choiceInput = stdin.readLineSync()?.trim();
if (choiceInput == null || choiceInput.isEmpty) choiceInput = '1';
if (choiceInput == '4') {
startApiGenerate();
return;
}
if (choiceInput == '5') {
stdout.write('Enter folder path: ');
String? folderPath = stdin.readLineSync()?.trim();
if (folderPath == null || folderPath.isEmpty) {
print('Error: Folder path is required!');
return;
}
startBatch(folderPath);
return;
}
// 1. Get JSON file path
stdout.write('Enter JSON file path (default: response.json): ');
String? jsonPath = stdin.readLineSync()?.trim();
if (jsonPath == null || jsonPath.isEmpty) {
jsonPath = 'response.json';
}
// 2. Parse JSON
dynamic json;
try {
_progress.start('Reading JSON file...');
json = JsonParser.parseFile(jsonPath);
_progress.success('JSON file detected: $jsonPath');
} catch (e) {
_progress.error('Error: $e');
return;
}
if (choiceInput == '6') {
_handleSync(json);
return;
}
// Get Model Name
stdout.write('Enter model name: ');
String? modelNameInput = stdin.readLineSync()?.trim();
if (modelNameInput == null || modelNameInput.isEmpty) {
print('Error: Model name is required!');
return;
}
final modelName = StringUtils.capitalize(modelNameInput);
_runGeneration(json, modelName, choiceInput, false);
}