A Very Opinionated Flutter Project Template
Powered by the Very Good CLI 🤖
Please check other branch to see other template.
- Mobile (Not available yet)
- Multiplatform (Not available yet)
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.template
to your liking. - 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.
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.
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
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
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
...
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
...
This project relies on flutter_localizations and follows the official internationalization guide for Flutter.
- To add a new localizable string, open the
app_en.arb
file 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);
}
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>
...
- 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
.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"
}
}