A production-ready Flutter boilerplate following Clean Architecture principles with BLoC state management, modular design, and comprehensive component system.
- Features
- Architecture
- Project Structure
- Getting Started
- Module System
- State Management
- Components
- Development Guide
- Best Practices
- Contributing
- Clean Architecture - Separation of concerns with data, domain, and presentation layers
- BLoC Pattern - Predictable state management with flutter_bloc
- Module System - Feature-based modular architecture with dependency injection
- Form Validation - Type-safe form validation with FormZ
- Internationalization - Multi-language support with flutter_localizations
- Theme Support - Dark/Light theme with custom theming
- Network Layer - Dio-based HTTP client with error handling
- Local Storage - Hive for local data persistence
- Component Library - Comprehensive reusable UI components (Atoms, Molecules, Organisms)
- Multi-Flavor - Development, Staging, and Production environments
- Error Tracking - Global error handling and monitoring
- Offline Support - Local caching with connectivity detection
This project follows Clean Architecture with three main layers:
βββββββββββββββββββββββββββββββββββββββββββββββ
β Presentation Layer β
β (Pages, Widgets, BLoCs, FormZ) β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββββββββββββ
β Domain Layer β
β (Entities, UseCases, Repository Interfaces)β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββββββββββββ
β Data Layer β
β (Models, Repositories, Data Sources) β
βββββββββββββββββββββββββββββββββββββββββββββββ
- Presentation: UI components, state management (BLoC), form validation (FormZ)
- Domain: Business logic, entities, use cases, repository contracts
- Data: API integration, local storage, repository implementations
lib/
βββ app/ # Application configuration
β βββ config.dart # App-wide configuration
β βββ flavor.dart # Environment flavors (dev, stag, prod)
β βββ locator.dart # Dependency injection setup
β βββ modules.dart # Module registration
β βββ app.dart # Root app widget
βββ core/ # Core functionality
β βββ components/ # UI component library
β β βββ atom/ # Basic building blocks (Text, Skeleton)
β β βββ molecule/ # Composite components (Buttons, Inputs)
β β βββ organism/ # Complex components (Cards, Pickers)
β βββ constants/ # App-wide constants
β βββ data/ # Core data utilities
β βββ exceptions/ # Custom exceptions
β βββ extensions/ # Dart/Flutter extensions
β βββ failures/ # Error handling
β βββ helpers/ # Helper functions
β βββ module/ # Module system base
β βββ networks/ # HTTP client configuration
β βββ pages/ # Common pages (Splash, Error)
β βββ preferences/ # Local storage
β βββ usecases/ # Base use case classes
β βββ utils/ # Utility functions
βββ features/ # Feature modules
β βββ auth/ # Authentication feature
β β βββ data/
β β β βββ models/
β β β βββ repositories/
β β β βββ sources/
β β βββ domain/
β β β βββ entities/
β β β βββ repositories/
β β β βββ usecases/
β β βββ presentation/
β β β βββ blocs/
β β β βββ formz/
β β β βββ pages/
β β β βββ widgets/
β β βββ module.dart
β βββ home/ # Home feature
β βββ settings/ # Settings feature
βββ l10n/ # Internationalization
β βββ app_en.arb
β βββ app_id.arb
βββ main_dev.dart # Dev environment entry point
main_prod.dart # Prod environment entry point
- Flutter SDK:
^3.10.0 - Dart SDK:
^3.10.0 - IDE: VS Code or Android Studio
-
Clone the repository
git clone <repository-url> cd flutter_boilerplate
-
Install dependencies
flutter pub get
-
Generate code
flutter pub run build_runner build --delete-conflicting-outputs
-
Run the app
# Development flutter run -t lib/main_dev.dart # Production flutter run -t lib/main_prod.dart
The app supports multiple environments configured in lib/app/config.dart:
static const FlavorConfig<String> baseUrl = FlavorConfig<String>(
prod: 'https://api.production.com',
dev: 'https://api.development.com',
stag: 'https://api.staging.com',
);Each feature is a self-contained module with its own routes and dependencies.
-
Create module structure
features/your_feature/ βββ data/ β βββ models/ β βββ repositories/ β βββ sources/ βββ domain/ β βββ entities/ β βββ repositories/ β βββ usecases/ βββ presentation/ β βββ blocs/ β βββ pages/ β βββ widgets/ βββ module.dart βββ your_feature.dart -
Implement module.dart
class YourFeatureModule implements BaseModule { @override Future<void> inject(GetIt getIt) async { // Register data sources getIt.registerLazySingleton<YourRemoteSource>( () => YourRemoteSourceImpl(getIt()), ); // Register repositories getIt.registerLazySingleton<YourRepository>( () => YourRepositoryImpl(getIt()), ); // Register use cases getIt.registerLazySingleton(() => GetYourDataUseCase(getIt())); // Register BLoCs getIt.registerFactory(() => YourBloc(getIt())); } @override Map<String, Route<dynamic>> routes(RouteSettings settings) { return { YourPage.routeName: MaterialPageRoute( builder: (_) => const YourPage(), settings: settings, ), }; } }
-
Register in app/modules.dart
var appModules = <BaseModule>[ AuthModule(), SettingsModule(), HomeModule(), YourFeatureModule(), // Add here ];