flutter-mobile-clean-architecture-template
                                
                                 flutter-mobile-clean-architecture-template copied to clipboard
                                
                                    flutter-mobile-clean-architecture-template copied to clipboard
                            
                            
                            
                        Flutter Mobile Clean Achitecture Template
Flutter Clean Architecture Project Template: Basic Template
A Very Opinionated Flutter Project Template
Powered by the Very Good CLI ๐ค
Available Templates ๐
Please check other branch to see other template.
- Mobile (Not available yet)
- Multiplatform (Not available yet)
How to Use ๐ฎ
Using this template is easy.
- Choose template from branch.
- Press use this template button.
- Create your repository.
- Clone your repository.
- Rename package name from dev.adryanev.templateto your liking.
- Rename the project name from templateto your need.
Freezed Code generator.
This template optimizes freezed generator only to certain suffixes to improve build time. The available suffixes are:
- *.codegen.dart
- *.model.dart
- *.entity.dart
For blocs, it automaticly read inside blocs directory.
Snackbar Flash
You can use snackbar easily with FlashCubit. You can call context.displayFlash(message) to show a snackbar.
Getting Started ๐
This project contains 3 flavors:
- development
- staging
- production
To run the desired flavor either use the launch configuration in VSCode/Android Studio or use the following commands:
# Development
$ flutter run --flavor development --target lib/main_development.dart
# Staging
$ flutter run --flavor staging --target lib/main_staging.dart
# Production
$ flutter run --flavor production --target lib/main_production.dart
*Template works on iOS, Android, Web, Linux, and Windows.
Makefile Command ๐ป
This project is equipped with Makefile command to shorten command writing, to see available command please refer to Makefile.
Please change the Environment Variable such as: ${FIREBASE_EMAIL}, etc., in the file to your need.
To run the desired flavor either use the launch configuration in VSCode/Android Studio or use the following commands:
# run build_runner once
$ make build
# watch file change
$ make watch
# generate dev apk
$ make apk-dev
# generate staging apk
$ make apk-stg
# generate production apk
$ make apk-prod
# generate dev ipa
$ make ipa-dev
# generate staging ipa
$ make ipa-stg
# generate production ipa
$ make ipa-prod
# fix code
$ make fix
# check fix
$ make check-fix
Running Tests ๐งช
To run all unit and widget tests use the following command:
# Run test with coverage
$ flutter test --coverage --test-randomize-ordering-seed random
To view the generated coverage report you can use lcov.
# Generate Coverage Report
$ genhtml coverage/lcov.info -o coverage/
# Open Coverage Report
$ open coverage/index.html
Project Libraries & Plugins ๐
The project is already included some library to speed up the development process.
All the libraries above are compatible with Flutter 3.
Notes: *need to install flutter_gen
Project Structure ๐
...
assets
โโโ fonts                               # Non-Google fonts
โโโ google_fonts                        # Google fonts offline
โโโ icons                               # App icons
โโโ images                              # App images
lib
โโโ app
|   โโโ router
|   |   โโโ app_router.dart             # Application Router
|   โโโ view
|   |   โโโ app.dart                    # MainApp File
|   โโโ app.dart
โโโ core
|   โโโ di                              # Dependency Injection Module
|   โโโ domain                          # Base Classes for domain layer
|   โโโ utils                           # utilities, constants, and extensions
โโโ shared                              # Shared Entity, Models, Widget, Service
โโโ features
|   โโโ counter                         # Feature Counter
|   |   โโโ data
|   |   |   โโโ datasources             # Data source (network, local)
|   |   |   โโโ models                  # DTO / Payload Model
|   |   |   โโโ repositories            # Implementation of domain Repository
|   |   โโโ domain
|   |   |   โโโ entities                # Business Domain Entity
|   |   |   โโโ repositories            # Interface Repository
|   |   |   โโโ usecases                # Business Use Cases
|   |   โโโ presentation
|   |   |   โโโ blocs                   # Application Logic & State management
|   |   |   โโโ pages                   # Application pages
|   |   |   โโโ widgets                 # Common Widgets in Feature
โโโ l10n
โ   โโโ arb
โ   โ   โโโ app_en.arb                  # English Translation
โ   โ   โโโ app_id.arb                  # Indonesian Translation
โโโ bootstrap.dart                      # Common Main Bootstrap Script
โโโ main_development.dart               # Env Development main method
โโโ main_production.dart                # Env Production main method
โโโ main_staging.dart                   # Env Staging main method
test
โโโ app                                 # App Test
โโโ features
|   โโโ counter                         # Feature Counter Test
|   |   โโโ data
|   |   |   โโโ datasources             # Data source (network, local) test
|   |   |   โโโ models                  # DTO / Payload Model test
|   |   |   โโโ repositories            # Implementation repository test
|   |   โโโ domain
|   |   |   โโโ entities                # Business Domain Entity test
|   |   |   โโโ repositories            # Interface Repository test
|   |   |   โโโ usecases                # Business Use Cases test
|   |   โโโ presentation
|   |   |   โโโ blocs                   # Bloc Test
|   |   |   โโโ pages                   # Application pages test
|   |   |   โโโ widgets                 # Common Widgets in Feature test
โโโ helpers                             # Common Test Helpers
...
Working with Translations ๐
This project relies on flutter_localizations and follows the official internationalization guide for Flutter.
Adding Strings
- To add a new localizable string, open the app_en.arbfile atlib/l10n/arb/app_en.arb.
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    }
}
- Then add a new key/value and description
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    },
    "helloWorld": "Hello World",
    "@helloWorld": {
        "description": "Hello World Text"
    }
}
- Use the new string
import 'package:template/l10n/l10n.dart';
@override
Widget build(BuildContext context) {
  final l10n = context.l10n;
  return Text(l10n.helloWorld);
}
Adding Supported Locales
Update the CFBundleLocalizations array in the Info.plist at ios/Runner/Info.plist to include the new locale.
    ...
    <key>CFBundleLocalizations</key>
	<array>
		<string>en</string>
		<string>id</string>
	</array>
    ...
Adding Translations
- For each supported locale, add a new ARB file in lib/l10n/arb.
โโโ l10n
โ   โโโ arb
โ   โ   โโโ app_en.arb
โ   โ   โโโ app_id.arb
- Add the translated strings to each .arbfile:
app_en.arb
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    }
}
app_id.arb
{
    "@@locale": "id",
    "counterAppBarTitle": "Penghitung",
    "@counterAppBarTitle": {
        "description": "Teks yang tampil pada AppBar di Halaman Counter"
    }
}