dart pub add

Add is one of the commands of the pub tool.

$ dart pub add <package>[:<constraint>] [<package2>[:<constraint2>]... ] [options]

This command adds the specified packages to the pubspec as dependencies, and then gets the dependencies.

For example, the following command is equivalent to editing pubspec.yaml to add the http package, and then calling dart pub get:

$ dart pub add http

By default, dart pub add uses the latest stable version of the package from the site. For example, if 0.13.3 is the latest stable version of the http package, then dart pub add http adds http: ^0.13.3 under dependencies in the pubspec.

To add a dev dependency, use the --dev option:

$ dart pub add --dev test


For options that apply to all pub commands, see Global options.

-d, --dev

Adds the package as a dev dependency, instead of as a regular dependency.


Depends on the package in the specified Git repository.

$ dart pub add http --git-url=


With --git-url, depends on the specified branch or commit of a Git repo.

$ dart pub add http --git-url= --git-ref=tmpfixes


With --git-url, specifies the location of a package within a Git repo.


Depends on the package server at the specified URL.


Depends on a locally stored package.


Depends on a package that’s shipped with the specified SDK (example: --sdk=flutter).


By default, pub connects to the network to retrieve hosted packages (--no-offline). To use cached packages instead, use --offline. For details, see Getting while offline.

-n, --dry-run

Reports which dependencies would change, but doesn’t change any.


By default, pub precompiles executables in immediate dependencies (--precompile). To prevent precompilation, use --no-precompile.