3

With Flutter I use -dart-define in order set some environment variables for different API's I use in the flutter app. And I am able to retrieve them using String.fromEnvironment. I also use Flavors in order to set different App icons for both IOS and Android. This works fine but I end up with a very long build string e.g.

flutter build ipa --flavor=prod --dart-define BASE_URL=https://example-prod.com/ --dart-define API_PATH=/api/v2/ --dart-define OTHERVAR=blablabla --dart-define YETANOTHERVAR=blablablabla

What I am looking for is a way where I can type flutter build ipa --flavor-prod and a script or configuration setting (in gradle or xcconfig ... or another way) will also set the correct values for the --dart-define variables.

I've read a few articles and come across a few people asking the same thing, but I haven't found a proper answer. Most of them will answer that you can pick up the --dart-define values in the build script to get for example the AppName and use that in the build scripts, but I want it the other way around. e.g. If flavor=prod then -dart-define BASE_URL=https://example-prod.com

Mau
  • 63
  • 3
  • I have exactly the same question. I would like the flavor to tell which env variables to use. Having the two flags, --flavor & --dart-define might be prone to errors since the might not match – Iván Travecedo Jul 03 '23 at 14:19

0 Answers0