Jacob Phillips
Jacob Phillips

Reputation: 9264

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.

Upvotes: 2

Views: 1528

Answers (2)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657446

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

flutter_test:
  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.

Upvotes: 1

Coder
Coder

Reputation: 658

You should be able to do that. For example, if you look at the password plugin, you can see that it is usable on Flutter, Web, and Other, so you just have to make sure that your dependencies are common among all three and you should be good to go! If there is an issue about putting it on the pub.dart.org, you can first try to transfer your files from flutter to dart, along with your pubspec.yaml and all your other files and try to put it on now.

Upvotes: 0

Related Questions