Creating Flavors For Flutter

The dev variant of an application is a valuable tool for developers to test their code, debug, and make any necessary changes before releasing their app to the public. This environment is designed to provide developers with a safe sandbox to experiment and ensure their code works correctly before being released to the public.

Flutter Consultants from Flutter Agency suggest Dev variants can also be used to share your app with internal testers, who may still need to be ready to test the app in the production environment.

Flutter Flavors: An Overview

Flavors (also denoted as build configurations in iOS) enable developers to create multiple versions of their apps using the same source code. It could be used for various reasons, such as creating a full version of the app, a limited “free” version, or a version for testing experimental features.

Flutter_flavor enables developers to set up and customize various flavors for their projects quickly. The flavors can be named, colored, and located with a banner as desired. If the attribute name is left blank or undefined, the banner is not shown, allowing for more customization and versatility when creating different versions of an app.

Flutter consultants can use flavors to create two different versions of your Flutter app without writing separate codebases. For instance, you can use a flavor to establish a free version with essential features and ads, while the paid version can include extra features, different styling, and no ads. 

Additionally, flavors can be used to test new features before they are ready to be deployed to production. This way, you can define compile-time configurations and parameters that can be read at runtime to adjust the app’s behavior.

Requirements Of Flutter Flavors: 

Different flavors can be created to configure the app for different environments, such as development and production. For example, the development version of the app could target an API host at dev.api.myapp.com, while the production version of the app could point to api.myapp.com.

Rather than manually creating an application with values hardcoded into variables for each environment, it is best to use flavors and provide these values as configurations at build time.

Steps To Create Flutter Flavors In Ios:

To create a new Scheme for your project in Xcode, select Runner > New Scheme from the menu. A scheme defines how Xcode runs various actions. In this example, flutter consultants use the flavor and scheme are named free.

Under the Information tab at the endpoint of the Configurations dropdown, click the plus button to make a copy of each configuration (Debug, Release, and Profile) to generate new configurations for the free scheme. Create another duplicate of the existing configurations for each environment.

In the Runner project, click Manage Schemes, and a pop up window will open. Double-click the free scheme and, in the lower-left corner of the window, click Duplicate. It will create a copy of the existing scheme. Rename each configuration by adding -free at the end of the name and click OK to save the changes.

Utilizing Flutter Flavors In iOS: 

After establishing your free version, you can customize the product bundle identifiers for each flavor. A bundle identifier is a unique identifier for your app. The Debug-free identifier is set to come.flavor-test.free in this example. Check here steps to change the minimum iOS deployment target.

Add the suffix free to each- free scheme value to distinguish between flavors. It will make sure that each scheme has its distinct bundle identifier.

In the Build Settings, assign a specific Product Name for each flavor. For instance, set the Product Name for the Debug Free flavor. Then, add the display name to your Info. plist file, setting the Bundle Display Name value to $(PRODUCT_NAME).

To apply this setup, create a free scheme in Xcode and configure the build configurations for the scheme. For further details, please check out the Launching your app flavors section at the bottom of this document.

Plugin Configuration Used In This Process: 

If your application uses a Flutter plugin, you must modify the ios/Podfile to ensure that the same Xcode build configurations are used for the Debug, Profile, and Release builds.

To accomplish this, update the settings in the Podfile in the ios directory so that they reflect the Xcode build configurations for the free plan. Below is the coding which the flutter consultants use:

project ‘Runner,’ {

  ‘Debug-free’ => :debug,

  ‘Profile-free’ => :release,

  ‘Release-free’ => :release,

}

Applying Flutter Flavors In Android Devices: 

To configure flavors in Android, you must go to your project’s build—gradle file. Locate the file within the Flutter project at android/app/build.gradle. Create a flavorDimension to organize the product flavors that you’re adding. Gradle will not blend product flavors that share the same dimension. 

If flutter consultants use an applicationIdSuffix instead of an applicationId, the suffix will be appended to the base application id. Below is the coding:

flavorDimensions “default”

productFlavors {

    free {

        dimension “default”

        resValue “string”, “app_name”, “free flavor example”

        applicationIdSuffix “.free”

    }

}

Final Launch Configuration Of Flutter Flavor: 

To set up your project to run multiple environments, create the launch.json file in the .vscode folder in the root directory of your project. This file should contain configuration objects with names, requests, types, programs, and args keys. 

The name is the name of the configuration, the request is “launch”, the type is “dart”, the program is the path to your Flutter project’s main.dart, and the args key is the command line argument –flavor [environment name].

Once the launch.json file is created, you can use the command flutter run –flavor [environment name] to run the project in the specified environment.

Here is the coding which flutter consultants use:

{

  “version”: “0.2.0”,

  “configurations”: [

    {

      “name”: “free”,

      “request”: “launch”,

      “type”: “dart”,

      “program”: “lib/main_development.dart”,

      “args”: [“–flavor”, “free”, “–target”, “lib/main_free.dart” ]

    }

  ],

  “compounds”: []

}

You can now execute the terminal command flutter run –flavor free or create a run configuration in your integrated development environment (IDE).

Conclusion: 

The production version of the app requires a prod flavor. It is a version of the same application connected to the production backend and ready to be released publicly. Flavors allow us to create separate versions of our app for different purposes, which these consultants also use.

We can make a flavor for development, a flavor for production, and a flavor for a demo. This way, we can construct multiple versions of our app before submitting it for distribution on the App Store and Google Play.