๐ ๏ธ flutter_feature_gen
A simple Dart CLI tool to instantly scaffold Clean Architecture feature folders in your Flutter project.
Save time, stay consistent, and generate complete feature modules with one command!
๐ Installation
Install it globally via pub.dev:
dart pub global activate flutter_feature_gen
Make sure Dart's pub global bin is in your PATH (usually ~/.pub-cache/bin
).
If not, add this to your .bashrc
/ .zshrc
:
export PATH="$HOME/.pub-cache/bin:$PATH"
โ Usage
flutter_feature_gen <feature_name> [state_management] [options]
State Management Options
--riverpod
- Riverpod Notifier--bloc
- Bloc pattern (Event + State + Bloc)--cubit
- Cubit pattern (simplified Bloc)
Feature Options
--freezed
- Use Freezed for immutable models and state classes--test
- Generate comprehensive test files
๐๏ธ Generated Structure
lib/features/your_feature/
โโโ data/
โ โโโ datasources/
โ โ โโโ your_feature_remote_datasource.dart
โ โ โโโ your_feature_remote_datasource_impl.dart
โ โ โโโ your_feature_local_datasource.dart
โ โ โโโ your_feature_local_datasource_impl.dart
โ โโโ models/
โ โ โโโ your_feature_model.dart
โ โโโ repositories/
โ โโโ your_feature_repository_impl.dart
โโโ domain/
โ โโโ entities/
โ โ โโโ your_feature_entity.dart
โ โโโ repositories/
โ โ โโโ your_feature_repository.dart
โ โโโ usecases/
โ โโโ get_your_feature_usecase.dart
โโโ presentation/
โโโ controller/
โ โโโ [state_management_files]
โโโ screens/
โ โโโ your_feature_screen.dart
โโโ widgets/
โโโ your_feature_card.dart
Each folder includes boilerplate Dart files (models, repositories, use cases, screens, widgets, etc.).
๐ง Smart Naming
- Converts
meal-plan
,meal_plan
, orMeal Plan
โMealPlanModel
,MealPlanRepository
, etc. - Folder:
lib/features/meal_plan/
- Class Names:
MealPlanScreen
,MealPlanModel
, etc.
๐ก Example
Social Media App Features
# User feed with advanced state management
flutter_feature_gen "Social Feed" --riverpod --freezed --test
# Profile management
flutter_feature_gen "User Profile" --bloc --test
# Chat system
flutter_feature_gen "Chat" --cubit --freezed
Creates:
lib/features/chat/
chat_model.dart
chat_repository.dart
chat_screen.dart
- And more...
โก Optional: Use cf
as Shortcut
Add this to your .zshrc
or .bashrc
:
alias cf='flutter_feature_gen'
Then use:
cf workout_tracker
๐งช Test Generation
When using --test
, the script generates:
- Unit Tests: For all business logic components
- Widget Tests: For UI components
- Integration Tests: For complete workflows
- Mock Classes: Using Mocktail for clean testing
Example test structure:
test/features/your_feature/
โโโ data/
โ โโโ datasources/
โ โโโ models/
โ โโโ repositories/
โโโ domain/
โ โโโ entities/
โ โโโ repositories/
โ โโโ usecases/
โโโ presentation/
โโโ controller/
โโโ screens/
โโโ widgets/
๐ฆ Dependencies
The script automatically adds the required dependencies based on your choices:
Core Dependencies
dependencies:
dio: ^5.3.2
flutter_riverpod: # if --riverpod
flutter_bloc: # if --bloc or --cubit
freezed_annotation: # if --freezed
json_annotation:
Dev Dependencies
dev_dependencies:
flutter_test:
sdk: flutter
mocktail:
bloc_test: # if --bloc or --cubit
build_runner: # if using Freezed
freezed: # if --freezed
json_serializable:
๐ง Advanced Usage
Custom Feature Names
The script intelligently handles various naming conventions:
cf "user profile" # โ user_profile (snake_case files)
cf "UserProfile" # โ user_profile (snake_case files)
cf "User-Profile" # โ user_profile (snake_case files)
cf "User Profile API" # โ user_profile_api (handles multiple words)
Build Runner Integration
For Freezed-based features, don't forget to run:
dart dart run build_runner build --delete-conflicting-outputs
๐จ Customization
The script generates production-ready code with:
- โ Proper error handling
- โ Type safety
- โ Null safety compliance
- โ Clean separation of concerns
- โ Testable architecture
- โ Industry best practices
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License
MIT License ยฉ 2025 Jamal Sfenjeh
๐ Acknowledgments
- Inspired by Clean Architecture principles by Robert C. Martin
- Flutter community best practices
- Modern state management patterns
๐ Issues & Support
Found a bug or have a feature request? Please open an issue.
Made with โค๏ธ for the Flutter community
โญ Star this repo if it helped you!