-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add easy conditional import based on kIsWeb or dart lib #60466
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
Comments
A trick: import 'data:,' if (dart.library.ffi) 'package:ffi/ffi.dart'; Sadly it only works in compilers, the analyzer does not accept However, it's unlikely to ever be useful to conditionally import a library with no alternative. If you just If you do If you then compiler the program on a platform without That's why conditional imports assume that you always import some library, so that every possible import includes all the names that the library refers to. Because if they don't, the library won't work for that condition anyway. As for having an easier condition to check for If you want the code to be able to conditionally refer to names from an import, then that's closer to deferred imports, and would need to be a langauge feature (so in the language repo).
In a compilation where no conditional URI applies, the library is unimported. The It's not perfect. If one function checks that |
I need optional platform imports too: import 'dom.dart' when (dart.library.js_interop) as dom;
if (dom.isAvailable) {
dom.attachNodes(effect, firstNode, lastNode);
} |
If it works, it should work with platform libraries. So I'll open a language request for it. |
I think the language feature request covers all that this issue can ask for, and there is nothing that can be done by the SDK without a language change, so I'll close this issue and defer to dart-lang/language#4317. |
Currently, we need to do those checks to check if some imports can be used on the web:
It would be easier if it could be done like this:
or
and in the code check if the package is imported:
The text was updated successfully, but these errors were encountered: