4

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?

kaboc
  • 814
  • 1
  • 6
  • 23
  • I don't know about the import, but you can use the [Platform class properties](https://api.flutter.dev/flutter/dart-io/Platform-class.html#static-properties) to check which operating system your app is running, this gives you the possibility to make different widgets for each Platform. – EdYuTo Jul 04 '20 at 13:06
  • It seems that Desktop version of flutter also uses dart.library.io, so ```import 'foo.dart' if (dart.library.io) 'bar.dart'``` should work for mobile and Desktop, give it a try. – EdYuTo Jul 04 '20 at 13:16
  • What I'd like to do is to import a package suitable for each platform as I mentioned, "a particular package for desktop and not for mobile". – kaboc Jul 04 '20 at 13:34
  • That's the best I could come up with, we'll need someone else's help here. Sorry I couldn't help... – EdYuTo Jul 04 '20 at 14:59

1 Answers1

4

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

smorgan
  • 20,228
  • 3
  • 47
  • 55