PubDevProvider class

A PackageProvider that downloads Dart packages from a pub host (pub.dev by default, or a custom/private/mirror host) and resolves package: imports from the extracted archives — honoring version constraints from a project pubspec.

Web-compatible. It uses only web-safe libraries (http — which picks a browser client on the web —, archive in-memory decoding, pub_semver, yaml) and an in-memory PackageCache by default, so it runs both on the VM and on the web. There is no dart:io dependency here.

CORS on the web

A browser cannot fetch https://pub.dev cross-origin (pub.dev doesn't send permissive CORS headers, and archives are served from Google Cloud Storage). For a web integration, either point host at a CORS-enabled mirror, provide a proxying client, or set rewriteUrl to route every request through a CORS proxy — e.g.:

PubDevProvider(
  rewriteUrl: (u) => Uri.parse('https://my-cors-proxy/${u.toString()}'),
);

Transitive version resolution is best-effort (highest version satisfying the declared constraint), not a full dependency solver.

Implemented types

Constructors

PubDevProvider({String host = 'https://pub.dev', Client? client, PackageCache? cache, Map<String, VersionConstraint>? constraints, String? pubspecYaml, Uri rewriteUrl(Uri url)?})

Properties

cache PackageCache
Cache for downloaded archives (in-memory by default; disk on the VM).
final
hashCode int
The hash code for this object.
no setterinherited
host String
The package host base URL (e.g. https://pub.dev).
final
rewriteUrl Uri Function(Uri url)?
Optional hook to rewrite every outgoing request URL — e.g. to prepend a CORS proxy on the web.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

availablePackages() Future<Set<String>>
The set of package names this provider can serve (e.g. from a project's pubspec/package-config), used to pre-provision imports. May be empty if the provider resolves lazily.
override
close() → void
Closes the underlying HTTP client (only if this provider created it).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolvePackage(String pkg, String libPath) Future<PackageSource?>
Resolves the source for package:[pkg]/[libPath], or null if this provider can't serve it.
override
resolvePackageUri(PackageUri uri) Future<PackageSource?>
Resolves a full package: import uri, or null.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited