Skip to the content.

Dart and Flutter (pub)

Use the proxy as the hosted pub repository. The examples use the upstream name pub; replace it with the name your operator gave the upstream (what you need).

   
Upstream type dart (alias pub)
Package source https://proxy.example.com/v1/pub
Clients dart pub (flutter pub uses the same client)
Tested Dart 3.5: in CI on every push and in the client lab. Flutter: not tested.

Configure

export PUB_HOSTED_URL=https://proxy.example.com/v1/pub
dart pub get

Authenticate

Only when the proxy has access control switched on. pub sends a bearer token to a hosted URL it has one for — your proxy token. With --env-var the token is read from an environment variable each time, and stored nowhere:

dart pub token add https://proxy.example.com/v1/pub --env-var PULLTHROUGH_TOKEN
export PULLTHROUGH_TOKEN="<token>"

Without --env-var, dart pub token add prompts for the token and stores it in pub’s own configuration (not tested).

Trust a private CA

dart pub uses the system trust store and nothing else. Neither SSL_CERT_FILE nor the Dart VM’s --root-certs-file reaches it; with only those set, dart pub get fails with a TLS error. Add the CA to the store — on Debian and Ubuntu:

cp /etc/ssl/corp-ca.pem /usr/local/share/ca-certificates/corp-ca.crt

followed by update-ca-certificates.

Check that it works

dart pub get succeeds, and pubspec.lock names the proxy for every hosted package (below). dart pub get -v prints every request.

Good to know

On the proxy

upstreams:
  pub:
    type: dart
    url: https://pub.dev

Version listings are served live with their archive URLs rewritten to the proxy (which is why server.publicUrl must be set); archives are cached immutably. Details: backends: dart.