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

Options

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.
--git-url=git_repo_url
Depends on the package in the specified Git repo.
$ dart pub add http --git-url=https://github.com/my/http.git
--git-ref=branch_or_commit
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
--git-path=directory_path
With --git-url, specifies the location of a package within a Git repo.
--hosted-url=package_server_url
Depends on the package server at the specified URL.
--path=directory_path
Depends on a locally stored package.
--sdk=sdk_name
Depends on a package that's shipped with the specified SDK (example: --sdk=flutter).
--[no-]offline
Uses cached packages instead of the network.
-n, --dry-run
Reports which dependencies would change, but doesn't change any.
--[no-]precompile
Precompiles executables in immediate dependencies (true by default).