Goals
My application will have two different flavors , `UAT` and `Production`, and each flavor will have some different settings, for example
- bundle ld
- app name
- icon
- base url
We will set up our apps together according to the following table
Setting different flavor needs to be set independently for different platform(Android & iOS), which is not an easy job you need to have a certain understanding of iOS and Android native development.
Until I found this library, it can help people easily create flavors in the flutter application
Getting Started
- Save app icon to flutter assets folder
2. flutter_flavorizr is intended to support development of Dart projects. In general, put it under dev_dependencies, in your pubspec.yaml
3. Create custom flavors based on the table above.
flutter_flavorizr supports many customization settings, please see this link for details.
flutter_flavorizr default processors set is this, if you want skip or only run single processors, you can custom processors set see this
Usage
When you finished defining the flavorizr configuration, you can proceed by running the script with:
flutter pub run flutter_flavorizr
// or only run custom set of processors
flutter pub run flutter_flavorizr -p ide:config
flutter_flavorizr will generate a lot of files for different platforms (Android & iOS) based on your pubspec.yaml config
Now it works fine
# production flavor
flutter run --flavor production -t lib/main_production.dart
# uat flavor
flutter run --flavor uat -t lib/main_uat.dart
Improvements
I found some files are redundant, so you can delete them yourself
- [iOS] CFBundleDisplayName is not replaced by $(BUNDLE_NAME) variable
2. [iOS] Delete the following files that are not useful
3. [iOS] Delete the {env}LaunchScreen
generated by flutter_flavorizr default
4. [iOS] Delete unused Assets
5. rename flavors.dart
to env_config.dart
and add baseUrl
Result
Source code:
Other good articles
I hope you enjoy reading this article and hitting clap 👏 .