fantasyrock2020/init-flutter-project
A Flutter boilerplate project provides a starter Flutter project organized with Clean Architecture and SOLID principles. Supported by tool, so you can generate structure quickly. Bloc + GetIt + GoRouter + Fastlane + CICD
Flutter Clean Architecture Project
A Flutter project following Clean Architecture principles and SOLID design patterns, with a modular structure for scalability and maintainability.
๐ Table of Contents
- Overview
- Architecture
- Project Structure
- Features
- Getting Started
- Renaming the Project
- Development Tools
- Code Generation
๐ฏ Overview
This project is built using Flutter and implements Clean Architecture with clear separation of concerns across three main layers:
- Presentation Layer: UI components, BLoC/Cubit for state management
- Domain Layer: Business logic, Use cases, Repository interfaces
- Data Layer: Repository implementations, Data sources, Models
The project uses a modular approach with separate packages for domain, data, core, and shared components, making it easy to maintain and scale.
๐๏ธ Architecture
Clean Architecture Layers
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Presentation Layer โ
โ (Features, BLoC, Widgets) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโ
โ Domain Layer โ
โ (Entities, Use Cases, Repositories)โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโ
โ Data Layer โ
โ (Models, Data Sources, Repos) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Principles
- Dependency Rule: Dependencies point inward (Presentation โ Domain โ Data)
- Separation of Concerns: Each layer has a single responsibility
- Testability: Business logic is independent of frameworks
- Maintainability: Changes in one layer don't affect others
๐ Project Structure
project_structure/
โโโ lib/ # Main application code
โ โโโ core/ # Core functionality
โ โ โโโ bloc/ # Base BLoC classes and common BLoCs
โ โ โโโ constants/ # App constants
โ โ โโโ enums/ # Enumerations
โ โ โโโ extensions/ # Extension methods
โ โ โโโ routing/ # Navigation configuration
โ โ โโโ asset_generator/ # Generated assets
โ โโโ di/ # Dependency injection setup
โ โโโ features/ # Feature modules
โ โ โโโ my_app.dart # Root app widget
โ โโโ widget/ # Shared widgets
โ
โโโ domain/ # Domain layer (package)
โ โโโ lib/
โ โโโ entities/ # Business entities
โ โโโ repositories/ # Repository interfaces
โ โโโ usecases/ # Business use cases
โ
โโโ data/ # Data layer (package)
โ โโโ lib/
โ โโโ datasource/ # Data sources
โ โ โโโ api/ # Remote API
โ โ โโโ local/ # Local storage
โ โโโ models/ # Data models
โ โโโ repositories/ # Repository implementations
โ
โโโ packages/ # Shared packages
โ โโโ core/ # Core utilities
โ โโโ shared/ # Shared UI components
โ
โโโ .tools/ # Development scripts
โ โโโ generate_model.sh # Generate model files
โ โโโ generate_repository.sh # Generate repository files
โ โโโ generate_structure.sh # Generate feature structure
โ
โโโ android/ # Android platform files
โโโ ios/ # iOS platform files
โโโ web/ # Web platform files
โโโ macos/ # macOS platform files
โโโ linux/ # Linux platform files
โโโ windows/ # Windows platform files
โจ Features
Current Features
- Theme Management: Light/Dark theme support
- Internationalization: Multi-language support
- Routing: Navigation with GoRouter
State Management
- BLoC Pattern: Using
flutter_blocfor state management - Base BLoC: Reusable base classes for common functionality
- Status Management: Centralized status handling
๐ Getting Started
Prerequisites
- Flutter SDK (>=3.10.0)
- Dart SDK (>=3.10.0)
Installation
-
Clone the repository
git clone <repository-url> cd project_structure
-
Install dependencies
flutter pub get
-
Install dependencies for packages
cd domain && flutter pub get && cd .. cd data && flutter pub get && cd .. cd packages/core && flutter pub get && cd ../.. cd packages/shared && flutter pub get && cd ../..
-
Generate code
dart run build_runner build --delete-conflicting-outputs
-
Run the app
flutter run
๐ Renaming the Project
To rename this project from project_structure to your desired project name, follow these steps:
Step 1: Rename the Root Directory
# Navigate to the parent directory
cd ..
# Rename the project directory
mv project_structure your_project_name
cd your_project_nameStep 2: Update pubspec.yaml
Update the name field in the root pubspec.yaml:
name: your_project_name # Change from 'project_structure'
description: "Your project description"Step 3: Update Import Statements
Search and replace all import statements that reference project_structure:
# Find all occurrences
grep -r "project_structure" --include="*.dart" .
# Replace in all Dart files (use your preferred method)
# Option 1: Using sed (macOS/Linux)
find . -name "*.dart" -type f -exec sed -i '' 's/project_structure/your_project_name/g' {} +
# Option 2: Using find and replace in your IDE
# Search: project_structure
# Replace: your_project_nameStep 4: Update Android Configuration
android/settings.gradle:
rootProject.name = 'your_project_name' // Update if neededandroid/app/build.gradle:
applicationId "com.example.your_project_name" // Update package nameStep 5: Update iOS Configuration
ios/Runner.xcodeproj/project.pbxproj:
- Search for
project_structureand replace withyour_project_name
ios/Runner/Info.plist:
- Update
CFBundleNameandCFBundleDisplayNameif needed
Step 6: Clean and Rebuild
# Clean build files
flutter clean
# Get dependencies again
flutter pub get
# Generate code
dart run build_runner build --delete-conflicting-outputs
# Verify the project works
flutter runNote: After renaming, make sure to test the app on all target platforms (Android, iOS, Web, etc.) to ensure everything works correctly.
๐ ๏ธ Development Tools
Scripts
Make scripts executable:
cd .tools && chmod +x generate_model.sh generate_repository.sh generate_structure.shGenerate Model
./generate_model.shGenerate Repository
./generate_repository.shGenerate Feature Structure
./generate_structure.sh๐ง Code Generation
Generate all code:
dart run build_runner build --delete-conflicting-outputsWatch mode (auto-regenerate on changes):
dart run build_runner watch --delete-conflicting-outputsGenerate for specific files:
dart run build_runner build --build-filter "lib/features/**"Happy Coding! ๐