Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get flavor name on Flutter?

Tags:

flutter

dart

Is it possible to get flavor name Flutter side? for both android and ios

build.gradle

flavorDimensions "app"

productFlavors {
    dev {
        dimension "app"
        versionCode 2
        versionName "1.0.0"
    }
    qa {
        dimension "app"
        applicationId "com.demo.qa"
        versionCode 3
        versionName "1.0.2"
    }
}
like image 422
BIS Tech Avatar asked Mar 10 '20 01:03

BIS Tech


1 Answers

As long as every flavor has a different packageName you could do it like this:

enum EnvironmentType { dev, qa }

class Environment {
  EnvironmentType current;

  Environment() {
    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      switch (packageInfo.packageName) {
        case "com.demo.qa":
          current = EnvironmentType.qa;
          break;
        default:
          current = EnvironmentType.dev;
      }
    });
  }
}
like image 79
Josh Avatar answered Sep 20 '22 23:09

Josh