Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Flutter app name depending on flavor?

I have development and production flavor for Flutter app.

Issue is label and launcher are same for both development and production app so cannot see difference. (Actually cannot install both on device at same time)

What is simple way to change Flutter app name depending on flavor?

I know can change app label and launcher by modify AndroidManifest.xml and Xcode info.plist. But this not simple: must make additional file for reference in xml and plist file. Modify like this is against aim of Flutter.

Anyone know solution?

Thanks!

like image 387
FlutterFirebase Avatar asked Feb 02 '19 21:02

FlutterFirebase


People also ask

How do you change the flavor in flutter?

The first step is to download google-services. json file(s) from each Firebase project to a temporary location at your machine. Next, create two folders android/app/src/dev and android/app/src/prod for each flavor. The Firebase configuration files go under their flavor folders under android/app/src/ folder..


Video Answer


2 Answers

Simply have this in android project app gradle :

flavorDimensions "default"
productFlavors {
    dev {
        resValue "string", "app_name", "AppName_DEV"
    }
    demo {
        resValue "string", "app_name", "AppName_Demo"
    }

    prod {
        resValue "string", "app_name", "AppName"
    }
}

and then in your AndroidManifest just use this :

android:label="@string/app_name"

it will generate unResolved app_name and it's done!

like image 117
Vahab Ghadiri Avatar answered Oct 17 '22 00:10

Vahab Ghadiri


For android create a directory under src for each flavor. Within each source create a directory named res, and in that create a directory named values.

Then in each values directory create a file named strings.xml

Add the following to the this file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">App 1</string>
</resources>

This creates a string named app_name that can be used in the Android Manifest.

To use the string change the android:label in the application tag in the AndroidManifest.xml, as follow:

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher">

Also add a default strings.xml into the main res values directory. Within that one set the value to something like "Default Flavor Res" to make you attend that the flavor doesn't have a resources file for strings.

Reference: http://cogitas.net/creating-flavors-of-a-flutter-app/

like image 6
The Tahaan Avatar answered Oct 16 '22 23:10

The Tahaan