dart pub add

Add is one of the commands of the pub tool.

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

This command adds the specified package to the pubspec as a dependency, and then gets the dependency. 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 pub.dev. For example, if 0.13.1 is the latest stable version of the http package, then dart pub add http adds http: ^0.13.1 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 repo.
$ dart pub add http --git-url=https://github.com/my/http.git
With --git-url, depends on the specified branch or commit of a Git repo.
$ dart pub add http --git-url=https://github.com/my/http.git --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).
Uses cached packages instead of the network.
-n, --dry-run
Reports which dependencies would change, but doesn't change any.
Precompiles executables in immediate dependencies (true by default).