-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Bug: Conditional Exports Do Not Detect Invalid Arguments #59575
Comments
Summary: Conditional exports in Dart fail when using multiple |
This looks like it's working as intended. You can write any sequence of dot-separated identifiers as the condition. It's not a Dart expression that is evaluated, it's a key into the compilation environment, so the export: export 'src/stub.dart'
if (Platform.isLinux) 'src/linux.dart'
if (Platform.isWindows) 'src/windows.dart'; will use The conditions are not invalid, they're just not configured. The conditional imports currently only work with keys of the form There are no available and usable compilation environment keys that expose the target platform. |
Thanks for the explanation. Then maybe this issue should have been turned into a documentation issue rather than being closed. Since I can't find any documentation related to this issue. The only documentation related to conditional imports I can find is here https://dart.dev/guides/libraries/create-packages#conditionally-importing-and-exporting-library-files and it does not go into any detail on what is going on or options available. It just gives a single example. |
Taking these statements, is it possible to pass keys to the compilation environment? flutter run --dart-define Platform.isLinux=true -d linux Does not seem to have any effect. |
A created a PR to improve the docs |
Improve conditional import/export docs Related to dart-lang/sdk#59575 --- Co-authored-by: Marya <[email protected]>
Conditional exports do not detect invalid
if(..)
statements. I created an example repo to show this:https://github.com/mcmah309/conditional_export_issue
Further:
If you replace the export in this file with either of the other commented out conditional exports, then the test will pass only on one platform instead of failing on both -
Original Failed CI Run: https://github.com/mcmah309/conditional_export_issue/actions/runs/11942744134
Linux Export First: https://github.com/mcmah309/conditional_export_issue/actions/runs/11942753955
Windows Export First: https://github.com/mcmah309/conditional_export_issue/actions/runs/11942761382
The expected behavior is to fail at compilation time for invalid
if(..)
statements. And hopefully allow platform compilation, like what is being attempted.The text was updated successfully, but these errors were encountered: