I think, the majority of packages is platform agnostic. Only packages with native plugin code need to declare their supported platform. Everything else should be good for all Flutter variants or even for pure Dart (server-side) code.
Well, if they import 'dart:html', they are basically web-only, unless that's behind a conditional import. Similarly, import 'dart:io' is available only on non-web platforms. So there is a bit of automation going on to detect that as I recall.
Yes, you are right. Developers should be always aware that an import of dart:io makes a package platform specific. For dart:html this is more obvious and there's even a linter warning, IIRC.
I work on pub.dev, and you only need to declare platform support if you are developing a Flutter plugin. That is something that has a native component to it.
If you're developing a pure-Dart package, you don't need to declare anything, platform support is inferred depending on:
If you are importing `dart:io`, `dart:html` or `dart:js`, etc.. because these don't work everywhere (can't use `dart:html` in Android, can't use `dart:io` on the web).
Transitive imports also count.
Conditional imports are however understood.
Only imports from the main library `package:mypkg/mypkg.dart` is considered, so you can ship IO specific bits in `package:mypkg/mypkg_io.dart` as is common.
If you depend on a package that is a plugin, then you're obviously limited by whatever platforms said plugin supports.
1
u/RandalSchwartz Feb 26 '21
Unfortunately, it's not automatic. You need to declare it in your pubspec before pub publish. So there are probably many packages that are already desktop-savvy but aren't so marked. (edit: see https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms for details.)