Skip to content

jamal-and/flutter_feature_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Clean Feature Generator

A powerful Bash script that generates complete Flutter features following Clean Architecture principles with support for multiple state management solutions and testing.

✨ Features

  • πŸ—οΈ Clean Architecture: Generates proper Data β†’ Domain β†’ Presentation layer structure
  • 🧠 Multiple State Management: Support for Riverpod, Bloc, and Cubit
  • ❄️ Freezed Support: Unified immutable models and state classes
  • πŸ§ͺ Test Generation: Complete test suite generation with proper mocking
  • πŸ“ Smart Naming: Automatic conversion from natural language to proper Dart conventions
  • ⚑ Zero Configuration: Works out of the box with sensible defaults

πŸš€ Quick Start

Installation Steps

git clone https://github.com/jamal-and/flutter_feature_generator.git
cd flutter_feature_generator
./install.sh
source ~/.zshrc    # or source ~/.bashrc

Basic Usage

# Generate a basic feature
cf "User Profile"

# Generate with Riverpod + Freezed + tests
cf "Shopping Cart" --riverpod --freezed --test

# Generate with Bloc + Equatable models + tests
cf "Product Details" --bloc --equatable --test

πŸ“‹ Command Syntax

cf <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

πŸ’‘ Example

Social Media App Features

# User feed with advanced state management
cf "Social Feed" --riverpod --freezed --test

# Profile management
cf "User Profile" --bloc --test

# Chat system
cf "Chat" --cubit --freezed

🎯 State Management Patterns

Riverpod Pattern

class UserProfileController extends Notifier<UserProfileState> {
  @override
  UserProfileState build() => const UserProfileState();

  Future<void> loadData() async {
    state = state.copyWith(isLoading: true);
    // Implementation...
  }
}

Bloc Pattern

class UserProfileBloc extends Bloc<UserProfileEvent, UserProfileState> {
  UserProfileBloc() : super(const UserProfileState.initial()) {
    on<_FetchData>((event, emit) async {
      emit(const UserProfileState.loading());
      // Implementation...
    });
  }
}

Cubit Pattern

class UserProfileCubit extends Cubit<UserProfileState> {
  UserProfileCubit() : super(const UserProfileState.initial());

  Future<void> loadData() async {
    emit(const UserProfileState.loading());
    // Implementation...
  }
}

πŸ§ͺ 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 suggests 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ 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!

About

A Bash Script to generate clean architecture Flutter features.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages