What is package
A package is a mechanism to encapsulate a group of programming units. The package manager for Dart is pub.
The package metadata is defined in a file, pubsec.yaml. YAML is the acronym for Yet Another Markup Language. The pub tool can be used to download all various libraries that an application requires.
Every Dart application has a pubspec.yaml file which contains the application dependencies to other libraries and metadata of applications like application name, author, version, and description.
No | Command & Description |
1 | ‘pub get’ Helps to get all packages your application is depending on. |
2 | ‘pub upgrade’ Upgrades all your dependencies to a newer version. |
3 | ‘pub build’ This is used for building your web application and it will create a build folder , with all related scripts in it. |
4 | ‘pub help’ This will give you help for all different pub commands. |
Description of the Commands
- pub get: This command is used to download and get all the packages and dependencies required for your Dart project. It checks your pubspec.yaml file for dependencies and downloads the latest version of all the packages.
Example:
// pubspec.yaml file
dependencies:
http: ^0.13.3
// Terminal
$ cd my_dart_project
$ pub get
- pub upgrade: This command is used to upgrade all the dependencies of your Dart project to the latest version. It checks the pubspec.yaml file for dependencies and updates them to the latest version available.
Example:
// pubspec.yaml file
dependencies:
http: ^0.13.3
// Terminal
$ cd my_dart_project
$ pub upgrade
- pub build: This command is used to build your Dart project for deployment. It compiles your code, resolves dependencies, and creates a build directory with all the required files. This command is mainly used for web applications.
Example:
// Terminal
$ cd my_dart_project
$ pub build
- pub help: This command is used to get help and documentation for all the different commands available in pub.
Example:
// Terminal
$ pub help