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!!!!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With