LinuxCommandLibrary

flutter-pub

Manage Dart and Flutter package dependencies

TLDR

Download/Update all packages specified in pubspec.yaml

$ flutter pub get
copy

Add a package dependency to an app
$ flutter pub add [package1 package2 ...]
copy

Remove a package dependency from an app
$ flutter pub remove [package1 package2 ...]
copy

Upgrade to the highest version of a package that is allowed by pubspec.yaml
$ flutter pub upgrade [package]
copy

SYNOPSIS

flutter pub subcommand [options]

PARAMETERS

--offline
    Forces pub to resolve dependencies using only the packages already in the local cache, without attempting to connect to the network. This is useful for working without an internet connection or ensuring reproducibility.

--dry-run
    Simulates the command's execution without making any actual changes to files or the system. This option is useful for previewing the effects of operations like adding, removing, or upgrading dependencies before committing them.

-v, --verbose
    Increases the verbosity of the output, displaying more detailed information about the command's execution process. This can be highly helpful for debugging issues or understanding complex operations.

--help
    Displays help information for the flutter pub command or for a specific subcommand if provided (e.g., flutter pub get --help). It shows available options and usage examples.

DESCRIPTION

The flutter pub command is an essential tool for managing dependencies and executing various tasks related to packages within a Flutter project. It acts as a wrapper around the Dart Pub package manager, integrating its powerful functionality directly into the Flutter workflow.

While flutter pub itself does not have many direct options, its power comes from its extensive set of subcommands, each designed for specific tasks such as fetching, updating, or publishing packages, running executables, managing global packages, and more. Users typically invoke flutter pub followed by a subcommand and its specific options.

CAVEATS

The core functionality of flutter pub is exposed through its subcommands, and most options are specific to these subcommands rather than to the main flutter pub command itself.

For most operations, ensure you are in the root directory of your Flutter project (where the pubspec.yaml file is located), as commands operate on the project's defined dependencies.

KEY SUBCOMMANDS

While the 'parameters' section outlines common options, the primary utility of flutter pub stems from its versatile subcommands:
get: Downloads all dependencies listed in the pubspec.yaml file.
upgrade: Updates all dependencies in the pubspec.yaml to their latest compatible versions.
add: Adds a new dependency to your pubspec.yaml and automatically runs pub get.
remove: Removes an existing dependency from your pubspec.yaml and automatically runs pub get.
publish: Publishes the current package to the pub.dev package repository, making it available to others.
run: Executes a script or program defined in a package listed in your pubspec.yaml.
global: Manages globally activated Dart packages, allowing their executables to be run from any directory.
outdated: Lists dependencies that have newer versions available than currently used.
deps: Prints a detailed dependency graph of your project, showing all transitive dependencies.

PUBSPEC.YAML FILE

The pubspec.yaml file is central to flutter pub's operation. It defines a Flutter project's metadata, its declared dependencies (including regular and dev dependencies), asset specifications, and other project-specific configurations. All flutter pub commands read from and/or modify this file to manage the project's external package requirements effectively.

HISTORY

The pub package manager has been a foundational component of the Dart ecosystem since its inception, facilitating robust dependency management for all Dart projects. As Flutter emerged as a prominent UI toolkit built on Dart, the pub command was seamlessly integrated into the Flutter SDK as flutter pub. This integration ensures that Flutter developers have a consistent and powerful tool for managing their project's external libraries and packages, leveraging the vast ecosystem of the Dart package repository (pub.dev).

SEE ALSO

flutter(1), dart(1)

Copied to clipboard