I have added the flutter module in an android project, and now I want to use a different entry file for flutter based on android flavor.

like:-

for stage flavor : main.stage.dart

prod flavor : main.prod.dart

is there any way to do that?

OR

How could I initialize environment variables in flutter based on the android flavor?

OR

While adding flutter to an existing android app, How could I use a different base URL in flutter_module based on stage, prod android flavor?

1

There are 1 answers

1
Pablo Johnson On

I haven't tried but I think you could do something like this

Create a run configuration for each flavor and write in the Additional arguments field:

--flavor stage --dart-define=app.flavor=stage
  • The first command is for telling the build command which flavor it is going to build.
  • The second command is for creating a variable that you will retrieve later in the dart side

Then in the dart side, you can retrieve the value in this way

const String flavor = String.fromEnvironment('app.flavor');

And based on the value of the string flavor you can decide what to do.

if you want to build your app by console the complete command should look like this

flutter build apk/ios --flavor stage --dart-define=app.flavor=stage