Dart `pubspec.yaml`: Have one part of the package use Flutter without the whole package depending on Flutter


I’m trying to create a package that works across Flutter, Web, and Other on pub.dart.org. As long as the default file in the package does not have platform dependencies, other files can do so without causing the whole package to be platform dependent. This works when one file uses dart:io and another uses dart:html, as long as the default import does not do that.

However, adding any sort of dependency on Flutter, say because there’s a single file in the package that uses it, causes pub.dart.org to list the package as Flutter only.

I believe it has something to do with the fact Flutter actually requires an SDK in pubspec.yaml, but I haven’t been able to find any further information about this.


Because web/io and Flutter use different Dart SDKs this causes troubles.
If pubspec.yaml contains

  sdk: flutter

the non-Flutter pub tool will reject the package.

You can try to leave that out from the shared package.

If that doesn’t work, you need to extract the libraries that depend directly on the Flutter SDK into a separate package.

Answered By – Günter Zöchbauer

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.