getBoolean/flutter_boolean_template
gehe zu github herunterladenflutter_boolean_template
An opinionated starting point for a Flutter app intended to provide the boilerplate
needed to create a large app and provides utilities to separate code generation into
separate packages.
Table of Contents
- Motivation
- About
- Demo
- Template: Getting Started
- Setup
- Testing
- Building
- Architecture
- Libraries
- Contributing
Motivation
This is an opinionated template I use for my personal projects. It uses melos
monorepo
to separate the code generation into separate packages for assets/, env/,
and localization/
This repository also follows Riverpod App Architecture,
I highly recommend reading the article. Each layer
has its own folder per feature in the lib/src/features/ folder.
About
- Made with Flutter
- Template by @getBoolean
- Minimal OS Version:
- iOS: 13.0
- Android: 6.0 (SDK 23)
- MacOS: 10.14.6
- Windows 10
- Linux: Any modern distribution
Demo
Flutter Web is deployed to GitHub Pages in a separate subfolder for each branch. The main
branch is deployed to
getboolean.github.io/flutter_boolean_template.
- This GitHub Pages setup requires the Flutter
#
from HashUrlStrategy, so ensure it is not disabled for your Flutter Web CI builds deployed to GitHub Pages. If it is disabled, the Navigator 2.0 subroutes will prevent GitHub Pages from resolving the correct app when refreshed.
For example, in the CI workflow using the argument --dart-define ENABLE_HASH_URL_STRATEGY=true
void main() {
const useHashUrlStrategy = bool.fromEnvironment('ENABLE_HASH_URL_STRATEGY', defaultValue: false);
if (!useHashUrlStrategy) {
setUrlStrategy();
}
runApp(MyApp());
}
Template: Getting Started
- Setup:
- [ ] Run
melos bootstrap
to install dependencies for all packages and generate env files. - [ ] Rename App: Change App/Package Name
- [ ] Workflow Permissions
- [ ] Update Description: pubspec.yaml and README.md.
- [ ] Replace codemagic.io badge with your own.
- [ ] Add Environment Variables: ENVied Environment Variables section for details.
- [ ] Change App Icon: flutter_launcher_icons
- [ ] Change Splash Screen: flutter_native_splash
- [ ] Setup the release build configuration, see the Building section.
- [ ] Setup Codecov for the repository, see the Codecov documentation.
- [ ] Update contribution guidelines at the Contributing section.
- [ ] (Important!) Update the LICENSE file. I give permission to relicense any
code provided in this template, but the licenses of the packages must still be followed. - [ ] Delete this
Template: Getting Started
section from the README.
Change App/Package Name
-
[ ] Run the following command to change the package name, where
com.author.app_name
is the new name for the app.dart run change_app_package_name:main com.author.app_name
-
[ ] Search for
getBoolean/flutter_boolean_template
and update it with your GitHub username and repository name -
[ ] Search for
com.example.flutter_boolean_template
and replace it with your new Android bundle identifier -
[ ] Search for
com.example.flutterBooleanTemplate
and replace it with your new iOS bundle identifier -
[ ] Search for
flutter_boolean_template
and replace it with your new package identifier -
[ ] Search for
Flutter Boolean Template
and replace it with your new app name
Workflow Permissions
- Github Repo: Settings -> Actions -> General -> Workflow permissions
- Enable “Read and write permissions”
- Enable “Allow GitHub Actions to create and approve pull requests”
- Github Repo: Settings -> Environments -> github-pages -> Deployment branches and tags
- Change “Selected branches and tags” to “No restriction”
- Github Repo: Settings -> Secrets and variables -> Repository secrets -> New repository secret
- Name:
PAT
- Value: Your GitHub Personal Access Token
- Github Profile -> Settings -> Developer settings -> Personal access tokens -> Tokens (classic)
- Generate a new token (classic), name it
<AppName> Web Deploy
, and give it therepo
andworkflow
scopes
- Name:
- Github Repo: Settings -> General -> Pull Requests -> Enable “Allow auto-merge”
Setup
- Install puro Flutter Environment Manager
- Install Flutter using Puro
- Install Melos globally
- Install Mason CLI
- Run
melos bootstrap
to install dependencies for all packages and generate env files.
Testing
- This project uses Mocktail to create mocks and fakes. Follow the instructions in the
Mocktail README. - Tests are located in the
test
root directory and each package. To run all tests, run the following command:
melos run test
Integration Tests
patrol
provides visual feedback to the tester andtakes screenshots automatically.
These integration tests are located in the integration_test
directory.
To run the tests, see the instructions in the Patrol documentation
Building
This project automatically builds for all platforms without code signing using GitHub Actions.
To build the project locally, follow the instructions in the
Flutter docs.
Flavors
Flavors are used to provide different environment variables based on the current flavor. By default,
the app uses the “local” flavor. Run/build the app with --dart-define FLAVOR=<flavorname>
to change the flavor. The following flavors are supported:
local
- Local development. The text banner changes to “Debug” when in debug mode, “Local” in profile mode, and hidden in release mode.dev
- Development build not intended for release.beta
- Beta build intended for release to testers.staging
- Staging build intended for device integration testing.prod
- Production build intended for release to stores.
Build for Windows Release
- Customize
msix_config
in pubspec.yaml according to the documentation
for msix for your method of publication. The default
configuration is for CI/CD testing builds only, not releases. - Run the corresponding command for your method of publication
Build for other platforms
- Flutter Docs for Android.
- Flutter Docs for iOS.
- Flutter Docs for MacOS.
- Flutter Docs for Linux.
- Flutter Docs for Web.
Architecture
This project uses the Riverpod App Architecture
in a feature-first manner where each feature is a separate package in the lib/src/features/ folder.
Each feature has its own layers, which separate the business logic from the UI.
Data Layer (Repositories)
The repository pattern consists of Repositories, DTOs, and Data Sources. Their jobs are the following:
- isolate domain models (or entities) from the implementation details of the data sources in the data layer.
- convert data transfer objects to validated entities that are understood by the domain layer
- (optionally) perform operations such as data caching.
Repository pattern use cases:
- talking to REST APIs
- talking to local or remote databases (e.g. Sembast, Hive, Firestore, etc.)
- talking to device-specific APIs (e.g. permissions, camera, location, etc.)
Domain Layer (Models)
Domain Models, which consist of entity and value objects. It should solve domain-related problems.
The domain models can contain logic for mutating them in an immutable manner, but they should not contain any serialization.
- Note: it is a simple data classes that doesn’t have access to repositories, services, or
other objects that belong outside the domain layer.
Presentation Layer (Controllers)
- holds business logic
- manage the widget state
- interact with repositories in the data layer
Application Layer (Service)
Implements application-specific logic by accessing the relevant repositories as needed.
The service classes are not concerned about:
- managing and updating the widget state (that’s the job of the controller)
- data parsing and serialization (that’s the job of the repositories)
Libraries
Melos
This project uses Melos to manage the monorepo.
flutter pub get
# Install melos globally
dart pub global activate melos
# Setup local dependency overrides for packages in the monorepo
melos bootstrap
# Or if dart executables are not on your path
dart pub global run melos bootstrap
Scripts
Pub:
melos run pub
- Runpub get
in all packages.melos run dart:pkg
- Rundart pub get
in the selected dart package.melos run flutter:pkg
- Runflutter pub get
in the selected flutter package.melos run upgrade
- Runpub upgrade
in all packages.melos run upgrade:pkg
- Runpub upgrade
in the selected package.
Code Generation:
dart run build_runner watch -d
- Watch and generate code for the app, does not work with subpackagesmelos run generate
- Runbuild_runner build
in all packages that depend onbuild_runner
.melos run generate:pkg
- Runbuild_runner build
for a specific package (exceptenvied
packages).melos run watch:pkg
- Runbuild_runner watch
for a specific package (exceptenvied
packages). It will not work if you choose “all” in the package selection prompt.melos run assets
- Runassets_gen build
in all packages that depend onassets_gen
.melos run assets:pkg
- Runassets_gen build
for a specific package.melos run env
- Runbuild_runner
in all packages that depends onenvied
.melos run env:pkg
- Runbuild_runner
in a specific package that depends onenvied
.melos run loc
- Runflutter gen-l10n
in the localization package to generate
the localized strings from the arb files.
Tests:
melos run lint
- Run dart analyzer and custom lints in all packages.melos run analyze
- Rundart analyze
in all packages.melos run custom_lint
- Rundart run custom_lint
in all packages.melos run test
- Run all Flutter tests.melos run format
- Rundart format
in all packages.melos run fix
- Rundart fix --apply
in all packages.melos run test
- Run all tests in the project.melos run flutter_test
- Run all Flutter tests in the project.melos run dart_test
- Run all Dart tests in the project.melos run flutter_test:pkg
- Run Flutter tests for a specific package.melos run dart_test:pkg
- Run Dart tests for a specific (Dart only) package.
GoRouter Navigation
This project uses GoRouter for navigation
and provides some starter boilerplate for adaptive multitab navigation using ResponsiveScaffold
.
ENVied Environment Variables
Environment variables are setup using ENVied
in the env package. Environment variables need to be
defined for debug, profile, and release modes.
- Copy the
*.env.example
files and remove the.example
extension from them. - Add the values for the environment variables in the respective
.env*
file.- Each key must be added to each
.env*
file, unless a non null default value is added
to the@EnviedField
annotation. - It is recommended to use an empty string for the default and use
Env
’s getter to access the value.
- Each key must be added to each
- Update src/env/app_env_fields.dart
with the new environment variables forAppEnvFieldsGenerated
andAppEnvFieldsNullable
. - Add the new environment variables to the implementing
*Env
classes in the src/env directory.- It must be done for all even if only one
.env
file is planned to be used
- It must be done for all even if only one
- Enable
obfuscate
for API keys in the@EnviedField
annotation. (Note: still assume it is not secure) - Optionally, add a
@EnviedField
defaultValue
or enableoptional
on the annotation for keys which are
not required in all modes.
Mason Bricks
Mason to generate code for features
and tests using templates. To use the bricks, install the Mason VS Code extension. To create
addition bricks, use Mason CLI.
JSON Serialization, Unions, Sealed Classes and copyWith
- dart_mappable
- Used for Unions, JSON serialization, and copyWith
- modddels
- Used for type-safe data validation, NOT serialization
State Management
This project is preconfigured to use Riverpod Generator.
The normal riverpod syntax is still supported. See Andrea’s article on
Riverpod architecture
for how to structure your code.
It is recommend to run build_runner in watch mode to generate the code for Riverpod.
dart run build_runner watch -d
Async Data Loading and Caching
The stock package is recommended for loading data from both remote and
local sources. Its main goal is to prevent excessive calls to the network and disk cache. By
utilizing it, you eliminate the possibility of flooding your network with the same request
while, at the same time, adding layers of caching.
Although you can use it without a local source, the greatest benefit comes from combining Stock with a local database such as Floor, Drift, Sqflite, Realm, etc. (excerpt from the README)
Native Splash Screen
Follow the instructions in the file flutter_native_splash.yaml
Native Platform Dialogs/Alerts
Use flutter_native_dialog to show native dialogs/alerts.
Bottom Sheets
Use wolt_modal_sheet to show customizable and responsive bottom sheets.
Layout List/Grid
Use wolt_responsive_layout_grid to show a responsive list/grid.
Contributing
- Fork it https://github.com/getBoolean/flutter_boolean_template/fork
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am ‘Add some fooBar’)
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request
![](/images/banner-woo.jpg)
herausragende projekte, die mit getBoolean/flutter_boolean_template zusammenhängen, empfohlener download
AppFlowy
47859
AppFlowy is an open-source alternative to Notion. You are in charge of your data and customizations. Built with Flutter and Rust.
localsend
33797
An open-source cross-platform alternative to AirDrop
spotube
23772
🎧 Open source Spotify client that doesn't require Premium nor uses Electron! Available for both desktop & mobile!
revanced-manager
15035
💊 Application to use ReVanced on Android
gsy_github_app_flutter
14559
Flutter 超完整的开源项目,功能丰富,适合学习和日常使用。GSYGithubApp系列的优势:我们目前已经拥有Flutter、Weex、ReactNative、kotlin 四个版本。 功能齐全,项目框架内技术涉及面广,完成度高,持续维护,配套文章,适合全面学习,对比参考。跨平台的开源Github客户端App,更好的体验,更丰富的功能,旨在更好的日常管理和维护个人Github,提供更好更方便的驾车体验Σ( ̄。 ̄ノ)ノ。同款Weex版本 : https://github.com/CarGuo/GSYGithubAppWeex 、同款React Native版本 : https://github.com/CarGuo/GSYGithubApp 、原生 kotlin 版本 https://github.com/CarGuo/GSYGithubAppKotlin
dio
12249
A powerful HTTP client for Dart and Flutter, which supports global settings, Interceptors, FormData, aborting and canceling a request, files uploading and downloading, requests timeout, custom adapters, etc.
gopeed
11832
A modern download manager that supports all platforms. Built with Golang and Flutter.
bloc
11441
A predictable state management library that helps implement the BLoC design pattern
getx
9899
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
flame
8846
A Flutter based game engine.
flutter_deer
7595
🦌 Flutter 练习项目(包括集成测试、可访问性测试)。内含完整UI设计图,更贴近真实项目的练习。Flutter practice project (including integration testing and accessibility testing). Contains complete UI design drawings for a more realistic practice project.
fish-redux
7343
An assembled flutter application framework.
hiddify-next
7232
Multi-platform auto-proxy client, supporting Sing-box, X-ray, TUIC, Hysteria, Reality, Trojan, SSH etc. It’s an open-source, secure and ad-free.
ente
6686
Fully open source, End to End Encrypted alternative to Google Photos and Apple Photos
fl_chart
6451
FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
pixez-flutter
6360
一个支持免代理直连及查看动图的第三方Pixiv flutter客户端
Flutter-Responsive-Admin-Panel-or-Dashboard
6355
Responsive Admin Panel or Dashboard using Flutter
aidea
6021
AIdea 是一款支持 GPT 以及国产大语言模型通义千问、文心一言等,支持 Stable Diffusion 文生图、图生图、 SDXL1.0、超分辨率、图片上色的全能型 APP。
riverpod
5828
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
pikapika
5463
美观易用且无广告的漫画和游戏客户端,同时支持MacOS,Windows,Android,iOS。