The easiest way to build flavors in Flutter (Android & iOS)

Wing CHAN
4 min readApr 24, 2022

Goals

My application will have two different flavors , `UAT` and `Production`, and each flavor will have some different settings, for example

  1. bundle ld
  2. app name
  3. icon
  4. 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

  1. 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

  1. [iOS] CFBundleDisplayName is not replaced by $(BUNDLE_NAME) variable

2. [iOS] Delete the following files that are not useful

--

--