-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a generated variable based on flavor #31441
Comments
This sounds like something that could be plumbed to |
We do have the --dart-defines option, but that isn't wired up for non-JavaScript targets yet. We could do something automatically, but for the most part the dart code doesn't depend on chosen flavor, so we'd introduce another angle of invalidation. This might waste some time if the flavor-dependent environment variable would otherwise not be used |
Is there an issue filed to wire up |
Now that #44483 is solved, what would happen next? |
In your code:
From command line:
This would print "paid" when run. |
That's wonderful. Are there any plans to avoid having to double-specify the flavor? |
doing this automatically would require us to fully invalidate a build whenever someone switched flavors. That might be surprising if someone wasn't using the actual constant value |
I think this can be scripted easily enough from the command line. closing as resolved |
@jonahwilliams Your proposed solution does not work if one tries to run an app on iOS (ex For some reason no dart defines are passed into the environment so that they could be subsequently read by String.fromEnvironment(...). It does seem to work on Android though, but with Android the main method can be defined in an arbitrarily named dart file and again as opposed to iOS the -t ... / --target=... arguments work perfectly well. I think observations by Denis Baketsky may be relevant here: https://medium.com/@tatsu.ukraine/what-you-should-know-before-you-upgrade-flutter-in-your-project-with-compile-time-variables-3ec3d2e9ba79
|
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
As today there is no hint to get what flavor is running in dart code. The current workaround is to use the
-t
flag in the build command to change the main file target, creating main_dev.dart and main_prod.dart per example.Would be nice to have some generated variable or something similar to expose which flavor is in compile time.
The text was updated successfully, but these errors were encountered: