Skip to content

ardi27/flutter-clean-architecture-template

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Flutter Clean Architecture Project Template: Basic Template

A Very Opinionated Flutter Project Template

coverage style: very good analysis License: MIT

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.

  1. Choose template from branch.
  2. Press use this template button.
  3. Create your repository.
  4. Clone your repository.
  5. Rename package name from dev.adryanev.template to your liking.
  6. Rename the project name from template to 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.

Category Library Name Link
State management bloc https://pub.dev/packages/bloc
flutter_bloc https://pub.dev/packages/flutter_bloc
bloc_concurrency https://pub.dev/packages/bloc_concurrency
Router go_router https://pub.dev/packages/go_router
Code Generator build_runner https://pub.dev/packages/build_runner
flutter_gen_runner* https://pub.dev/packages/flutter_gen_runner
flutter_native_splash https://pub.dev/packages/flutter_native_splash
Languange Feature dartz https://pub.dev/packages/dartz
rxdart https://pub.dev/packages/rxdart
equatable https://pub.dev/packages/equatable
freezed https://pub.dev/packages/freezed
freezed_annotation https://pub.dev/packages/freezed_annotation
change_case https://pub.dev/packages/change_case
intl https://pub.dev/packages/intl
uuid https://pub.dev/packages/uuid
crypto https://pub.dev/packages/crypto
JSON json_serializable https://pub.dev/packages/json_serializable
json_annotation https://pub.dev/packages/json_annotation
Dependency Injection get_it https://pub.dev/packages/get_it
injectable https://pub.dev/packages/injectable
injectable_generator https://pub.dev/packages/injectable_generator
Local Storage shared_preferences https://pub.dev/packages/shared_preferences
Logging logging https://pub.dev/packages/logging
Form Validation formz https://pub.dev/packages/formz/versions/0.5.0-dev.1
Widgets flutter_hooks https://pub.dev/packages/flutter_hooks
flutter_screenutil https://pub.dev/packages/flutter_screenutil
flutter_svg https://pub.dev/packages/flutter_svg
google_fonts https://pub.dev/packages/google_fonts
Testing mocktail https://pub.dev/packages/mocktail
bloc_test https://pub.dev/packages/bloc_test

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

  1. To add a new localizable string, open the app_en.arb file at lib/l10n/arb/app_en.arb.
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    }
}
  1. 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"
    }
}
  1. 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

  1. For each supported locale, add a new ARB file in lib/l10n/arb.
โ”œโ”€โ”€ l10n
โ”‚   โ”œโ”€โ”€ arb
โ”‚   โ”‚   โ”œโ”€โ”€ app_en.arb
โ”‚   โ”‚   โ””โ”€โ”€ app_id.arb
  1. Add the translated strings to each .arb file:

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"
    }
}

About

Flutter Clean Achitecture Template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 48.0%
  • C++ 24.7%
  • CMake 18.6%
  • HTML 4.7%
  • Makefile 2.3%
  • C 1.0%
  • Other 0.7%