Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Windows build flavor

I have a Flutter Windows app,and I want to build two flavor (dev and prod). But i don't konw how to build for windows. Is anybody know? Please tell me how to configure.

Thank you so much!!!!

like image 609
Jonty Avatar asked May 08 '26 15:05

Jonty


1 Answers

You can build your app with a dart-define that sets the flavor:

flutter build --dart-define FLAVOR=prod

In the app, you get it as a constant variable:

const String flavor = String.fromEnvironment("FLAVOR", defaultValue: "dev");

Note that "fromEnvironment" is related to the build environment here and has nothing to do with "normal" environment variables.

The fact that a dart-define is available as a constant value enables so-called tree shaking: conditions based on such constant values are optimized out of release builds. This is quite similar to what you would do in C / C++ with an ifdef in the resultin binary, while everything that is not "shaken out" is still made sure to compile.

like image 73
FourtyTwo Avatar answered May 10 '26 10:05

FourtyTwo