Flutter Flavoring — Android project using Firestore.

While developing an application, we can create different environments meant for developers, testers, and real users. Creating such an environment is the flavoring of an application.

Suppose, you have different environments having endpoints devapi.XYZ.com, testapi.XYZ.com and prodapi.XYZ.com . Now instead for hardcoding this values in our application, we can configure it to build app pointing to corresponding endpoints.

Let’s check how can we add flavor to flutter android app using cloud fire store.

How to configure a cloud firestore? please refer this link

Step 1: Create Flutter project (using name : add_flutter_app_to_firebase )

Step 2: We need to add following lines(shown in bold below) of code in android/app/build.gradle file.

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.yogita.add_flutter_app_to_firebase"
minSdkVersion 21
multiDexEnabled true
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

flavorDimensions "app"
productFlavors {
development {
dimension "app"
applicationIdSuffix ".dev"
staging {
dimension "app"
applicationIdSuffix ".staging"
production {
dimension "app"
applicationIdSuffix ""

buildTypes {
release {

As you can see in above code, applicationId for this project is “com.yogita.add_flutter_app_to_firebase”. In productFlavours, we have added development, staging and production environment. applicationIdSuffix for these flavors “.dev” , “.staging”. Just keeping null for production environment, these extensions are added to applicationId while integrating android project with firebase flavor project (more details in step 3)

Step 3: Create Firebase projects for different flavors

a. FlutterAppToFirebase — Dev for development flavor

In firebase project FlutterAppToFirebase — Dev, I have added “com.yogita.add_flutter_app_to_firebase.dev” as package name (repeat same for staging)

b. FlutterAppToFirebase — Staging for staging flavor

c. FlutterAppToFirebase for production.

for production applicationIdSuffix null so it take default package name “com.yogita.add_flutter_app_to_firebase”
projects for dev/staging/prod
screen shot to show .dev package name and .json file

Refer this link to learn more about creating firebase project and integration with flutter app.

Step 4: Now download google-service.json file for each flavor from firebase project (refer screenshot above)

In android/src folder, create a separate directory for each flavor and store the google-service.json file in respective folders.(see project structure below)

- app
- src
- development
- google-services.json
- production
- google-services.json
- staging
- google-services.json

It’s really important to store google-service.json file under separate folder, based on arguments used in flutter run, corresponding . json file is called and connects with respective firebased project.

Step 5: Now are ready with flavoring and we can start playing with different flavors executing below commands.

flutter run --flavor <flavor-name>

flavor-name can be development, staging, production as per our choice.

Keep coding!

Thank you!




Flutter Expert | Cloud Enthusiast | Full Stack Developer | .NET Developer |Coach and Trainer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How Does Android App Development Help You Build Customer Base?

The Deck — Part IV

Integration of Huawei Map kit in Navigation Glove IoT application Using Kotlin — Part 2

A Garbage Collection Story

Bottom Navigation and Navigation Drawer Using Scaffold from Jetpack Compose

How to build a SnapChat clone on Android

A Holistic Approach to Handling User Input in Android

How to Play Sound Effects in Unity

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yogita Kumar

Yogita Kumar

Flutter Expert | Cloud Enthusiast | Full Stack Developer | .NET Developer |Coach and Trainer

More from Medium

Navigator overview in Flutter.

Post image

Flutter — Cart Calculator App: Part 3

Using Firebase Storage in Flutter

Visual Reference: https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_tyjqozrEPY%2Fmaxresdefault.jpg&f=1&nofb=1

Using Huawei App Messaging in Flutter