Skip to content

πŸš€ Production-ready Flutter template with Clean Architecture, BLoC, Freezed, AutoRoute, multi-flavor support, and responsive design. Build scalable apps faster!

Notifications You must be signed in to change notification settings

yusriltakeuchi/flutter_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Flutter Template

Production-ready Flutter template with clean architecture

Flutter Dart License

Features β€’ Quick Start β€’ Structure β€’ Documentation


✨ Features

Feature Description
πŸ“± Platform Support Android & iOS ready
πŸ—οΈ DDD Architecture Clean, scalable code organization
🧊 Freezed Immutable models & unions
🎯 BLoC Pattern Predictable state management
πŸ—ΊοΈ AutoRoute Type-safe navigation
🌍 Multi-Flavor Dev, Staging, Production environments
πŸ’‰ Dependency Injection Modular & testable
πŸŒ“ Theme Support Light, Dark, System modes
πŸ”§ Error Handling Centralized failure management

πŸš€ Quick Start

1️⃣ Install Template

# Install copy_template globally
dart pub global activate copy_template

# Create your project
copy_template my_app https://github.com/yusriltakeuchi/flutter_template.git /path/to/folder

2️⃣ Setup Package Name

# Change package name
dart run change_app_package_name:main com.your.package

# Update flavor names in:
# - android/app/build.gradle (productFlavors)
# - utils/flavor/flavor_utils.dart

3️⃣ Run Project

flutter run --flavor dev

Available flavors: dev | staging | prod


πŸ“ Project Structure

lib/
β”œβ”€β”€ 🎯 bloc/               # State management
β”œβ”€β”€ βš™οΈ config/             # App configuration
β”œβ”€β”€ πŸ—οΈ core/               # Core utilities
β”‚   β”œβ”€β”€ components/        # Reusable widgets
β”‚   β”œβ”€β”€ constant/          # Constants
β”‚   β”œβ”€β”€ models/            # Core models
β”‚   └── networks/          # API client
β”œβ”€β”€ 🎨 domain/             # Business logic
β”‚   β”œβ”€β”€ cubit/             # Safe cubit base
β”‚   β”œβ”€β”€ dto/               # Data Transfer Objects
β”‚   β”œβ”€β”€ entities/          # Domain entities
β”‚   β”œβ”€β”€ models/            # Domain models
β”‚   └── repositories/      # Repository interfaces
β”œβ”€β”€ ✨ extension/          # Dart extensions
β”œβ”€β”€ πŸ”§ infrastructure/     # Data layer
β”‚   β”œβ”€β”€ datasource/        # Data sources
β”‚   └── repositories/      # Repository implementations
β”œβ”€β”€ πŸ’‰ injection/          # Dependency injection
β”œβ”€β”€ πŸ“± presentation/       # UI screens
β”œβ”€β”€ πŸ—ΊοΈ routing/            # Navigation
β”œβ”€β”€ 🎨 theme/              # App themes
└── πŸ› οΈ utils/              # Utilities

πŸ” Android Keystore Setup

Create android/key.properties:

storePassword=yourpassword
keyPassword=yourpassword
keyAlias=youralias
storeFile=/path/to/key.jks

🎨 Generate App Icons

This template uses flutter_launcher_icons with flavor support.

Generate Icons for All Flavors

# Generate for development flavor
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons.yaml

# Generate for staging flavor
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-staging.yaml

# Generate for production flavor
flutter pub run flutter_launcher_icons:main -f flutter_launcher_icons-prod.yaml

Configure Icons

Edit icon configurations in:

  • flutter_launcher_icons.yaml - Development flavor icons
  • flutter_launcher_icons-staging.yaml - Staging flavor icons
  • flutter_launcher_icons-prod.yaml - Production flavor icons
flutter_launcher_icons:
  android: true
  ios: true
  image_path: "assets/icons/your_icon.png"
  # Add more customization as needed

πŸ’‘ Tip: Place your icon files in assets/icons/ directory and update the image_path in the config files.


πŸ“š Documentation

πŸ“„ Create New Page

  1. Create screen in presentation/
  2. Add annotation:
    @RoutePage()
    class HomeScreen extends StatelessWidget {
      // Your screen code
    }
  3. Generate routes:
    make runner-build
  4. Register route in route.dart:
    @override
    List<AutoRoute> get routes => [
      AutoRoute(page: HomeRoute.page),
    ];

πŸŒ“ Theme Mode

Access theme with BlocBuilder<ThemeBloc>. Modes: light, dark, system

🎯 BLoC State Management

Use BlocBuilder with Freezed's when or maybeWhen for clean state handling:

// Using .when() - Handle all states
BlocBuilder<UserBloc, UserState>(
  builder: (context, state) {
    return state.when(
      initial: () => const IdleLoading(),
      loading: () => const LoadingListView(),
      error: (message) => ErrorWidget(message),
      loaded: (data) => DataView(data),
    );
  },
)

// Using .maybeWhen() - Handle specific states only
BlocBuilder<ThemeBloc, ThemeState>(
  builder: (context, state) {
    return state.maybeWhen(
      loaded: (mode) => YourWidget(mode),
      orElse: () => const CircularProgressIndicator(),
    );
  },
)

🎨 Dynamic Colors

Use context extensions for theme-aware colors:

// Auto-adapts to light/dark theme
Container(
  color: context.containerColor,
  child: Text(
    'Hello',
    style: TextStyle(color: context.blackWhiteColor),
  ),
)

Available colors:

  • context.isDark - Check if dark mode is active
  • context.blackWhiteColor - Black in light, white in dark
  • context.containerColor - Card/container background
  • context.backgroundColor - Screen background
  • context.greyDarkColor - Grey text colors

🌍 Access Current Flavor

flavor.current  // Returns: dev, staging, or prod

πŸ“ Responsive Sizing

Use AppSetting for responsive dimensions across all devices:

// Font Size - automatically adapts to screen size
Text(
  'Title',
  style: TextStyle(fontSize: AppSetting.setFontSize(16)),
)

// Width & Height
Container(
  width: AppSetting.setWidth(200),
  height: AppSetting.setHeight(100),
)

// Device dimensions
AppSetting.deviceWidth   // Full screen width
AppSetting.deviceHeight  // Full screen height

// Quick spacing
Space.w(16)  // Horizontal spacing
Space.h(20)  // Vertical spacing

// Device checks
AppSetting.isLargePhone(context)
AppSetting.isTablet(context)

πŸ“‘ Data Fetching Flow

  1. domain/entities β†’ Entity
  2. domain/dto β†’ DTO with Freezed & JSON serialization
  3. infrastructure/datasource/base β†’ API Extension
  4. infrastructure/datasource β†’ DataSource
  5. domain/repositories β†’ Repository Interface
  6. infrastructure/repositories β†’ Repository Implementation
  7. injection β†’ Register Dependencies
  8. bloc β†’ Create BLoC/Cubit
  9. presentation β†’ Build UI

🎨 IntelliJ File Templates

Speed up development with pre-built templates for Entity, DTO, and BLoC.

πŸ“₯ Download Templates

Installation:

  1. Download template file
  2. IntelliJ β†’ File β†’ Manage IDE Settings β†’ Import Settings
  3. Select downloaded file

πŸ”— Related Packages

assets_cleaner

Clean unused assets from your Flutter project automatically.


Made with ❀️ by Yusril Rapsanjani

⭐ Star this repo if you find it helpful!

About

πŸš€ Production-ready Flutter template with Clean Architecture, BLoC, Freezed, AutoRoute, multi-flavor support, and responsive design. Build scalable apps faster!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published