Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional package import for desktop in Flutter

I know that the availability of dart.library.html can be used as the condition for web, but what about desktop?

Although I suppose you can import a particular package for desktop and not for mobile if you create and use a new package in which different packages are specified for different platforms in pubspec.yaml as explained in the document, it seems a little redundant to make such a package for that purpose.

Is it possible just by using a statement of the import 'foo.dart' if (...) 'bar.dart' style, and if possible, what library is put in its if (...) part?

like image 299
kaboc Avatar asked Oct 13 '25 06:10

kaboc


1 Answers

You cannot use conditional imports to get different behavior between mobile and desktop; see this comment from the Dart team.

like image 184
smorgan Avatar answered Oct 14 '25 20:10

smorgan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!