flutter-pub
Manage Dart and Flutter package dependencies
TLDR
Download/Update all packages specified in pubspec.yaml
Add a package dependency to an app
Remove a package dependency from an app
Upgrade to the highest version of a package that is allowed by pubspec.yaml
SYNOPSIS
flutter pub <subcommand> [options]
PARAMETERS
add
Add a dependency to pubspec.yaml and run pub get
cache
Manipulate the local pub cache (repair, clean)
deps
Print the dependency graph as a tree
get
Resolve and fetch all dependencies
global
Manage globally activated packages
outdated
Analyze dependencies needing upgrades
remove
Remove a dependency from pubspec.yaml
run
Run an executable from a package
upgrade
Upgrade dependencies to latest compatible versions
--dry-run
Simulate without making changes
--verbosity=value
Set output verbosity (all, io, solver, error)
DESCRIPTION
flutter pub is the command-line interface for Pub, the package manager in the Dart and Flutter ecosystems.
It manages dependencies listed in pubspec.yaml, resolves transitive dependencies, downloads packages from pub.dev or other sources, and maintains a pubspec.lock file for reproducible builds.
Key functions include fetching packages (pub get), upgrading them (pub upgrade), inspecting dependency trees (pub deps), checking for outdated packages (pub outdated), and running package executables (pub run).
Pub uses a shared cache (~/.pub-cache) to avoid redundant downloads. It supports version constraints, dev dependencies, and global activations for CLI tools.
Essential for Flutter apps, it integrates seamlessly with flutter create and build processes, ensuring consistent environments across development, testing, and production.
Usage typically follows editing pubspec.yaml, then running flutter pub get. Supports offline mode and verbose logging for troubleshooting.
CAVEATS
Requires Flutter SDK in PATH; run flutter doctor first. Cache can grow large (~/.pub-cache). Offline mode limited without prior fetches.
COMMON WORKFLOW
Edit pubspec.yaml&br;flutter pub get&br;flutter pub deps (visualize)
FILES
pubspec.yaml: Dependencies&br>pubspec.lock: Locked versions&br>.packages: Resolved imports
HISTORY
Pub originated in Dart SDK (2013); integrated into Flutter at launch (2017). Evolved with Flutter 1.0 (2018) for mobile/web/desktop support.


