Provider To Flavor Flutter App.

Rao Muhammad Noman
3 min readNov 28, 2020

This article will help you to easily add multiple Flavor in you flutter application.

So why an app needs Flavour?

Suppose you have an application that has more than one mode. For example, you need to show different(change app theme) or test integration with different backend with a production environment. So how you do it? You change code for on new repo and manage it. But this is a bad approach because u need to handle a code for it as well. So what the best way to do it by using FLAVOR in your app.

Basically, the flavor can easily integrate into your application and you can add different configurations for a different environment. We use Provider to implement flavor in our flutter application.

Step #1:

flutter create <your project name>

Step # 2:

Add these files in you app lib folder.

Step # 3:

Step # 4:

Add an enum of name Flavor in flavor.dart which you need to add to your app.

Step# 5:

Add code in your main_dev.dart file

Step# 6:

Add code in your main_prod.dart file

Step# 7:

Add code in your main_staging.dart file

Step # 8:

Configuration For Android:

For android you need to add define Flavor Dimensions & Product Flavors in build.gradle.

Step #9:

Now you can run your app on a particular flavors by commands.

For Dev Flavor:

For Prod Flavor:

For Staging Flavor:

For iOS you need add schemes in your project .

Conclusion:

Now your app runs in a different environment. Different changes are done for different like for production you can run time URL change. Any different app icon for production flavor only.

--

--