generateModel method
Generates a standalone model class with optional Freezed/Equatable support.
name
- The name of the model to generate (e.g., 'user', 'product').
Creates a data model class in lib/shared/models/
with:
- Proper naming conventions (snake_case files, PascalCase classes)
- Freezed integration (if enabled in config)
- Equatable support (if enabled in config)
- JSON serialization support
- Appropriate imports and annotations
Example:
await fileGenerator.generateModel('user');
// Creates: lib/shared/models/user_model.dart
Implementation
Future<void> generateModel(String name) async {
final snakeName = templateGenerator.toSnakeCase(name);
// For standalone model generation, we'll put it in a shared models folder
await ensureDirectoryExists('lib/shared/models');
final content = templateGenerator.generateModel(name);
final filePath = 'lib/shared/models/${snakeName}_model.dart';
await writeFile(filePath, content);
print('✅ Generated model "$name":');
print(' - $filePath');
print('💡 Note: Model generated in shared folder. For feature-specific models, use "flx gen feature <name>"');
}