Flutter Clean Architecture Brick
A Mason brick to help you kickstart your Flutter app using clean architecture principles. This brick initializes your project with a predefined folder structure (e.g., core
and features
) and allows you to easily create new features with the necessary boilerplate files.
Features
- ποΈ Initialize your Flutter app with a clean architecture folder structure.
- β‘ Quickly add new features to your app with consistent boilerplate code.
- β¨ Customizable feature names to fit your project.
Folder Structure
The following folder structure will be created when initializing your app:
lib/ βββ features/ β βββ feature_name/ β β βββ data/ β β βββ domain/ β β βββ presentation/ βββ main.dart
yaml Copy code
Core
Holds shared error handlers, and reusable logic like use cases.
Features
Each feature gets its own folder, containing the following layers:
- Data: Handles data sources and repositories.
- Domain: Contains business logic (entities and use cases).
- Presentation: Manages UI and state (widgets, bloc, etc.).
How to Use
1. Add the Brick
To use this brick, add it to your Mason CLI:
mason add flutter_clean_arch
2. Initialize Your App
Run the following command to initialize your Flutter app with the predefined folder structure:
bash
Copy code
mason make flutter_clean_arch --init_app true
3. Add a New Feature
To generate a new feature, run:
bash
Copy code
mason make flutter_clean_arch --feature_name "YourFeatureName"
4. Example
Initializing the app:
bash
Copy code
mason make flutter_clean_arch --init_app true
This creates the folder structure and essential files for clean architecture.
Adding a feature named "Auth":
bash
Copy code
mason make flutter_clean_arch --feature_name "Auth"
This creates:
bash
Copy code
lib/features/auth/
βββ data/
βββ domain/
βββ presentation/
Variables
Variable Type Description Default
init_app boolean Initializes the app with the folder structure. false
feature_name string Name of the feature to be added. Template
Hooks
This brick includes hooks for automating additional tasks:
Pre-generation (pre_gen.dart): Validates user input and prepares for generation.
Post-generation (post_gen.dart): Installs essential dependencies for Flutter projects:
bloc
flutter_bloc
flutter_hooks
dartz
Dependencies Installation
If you initialize the app (init_app: true), the following Flutter packages are added automatically: