Dart Packages

In this tutorial you will learn about the Dart Packages and its application with practical example.

Dart Packages

Package is simply a set of dart program organized in an independent, reusable unit. It usually contains set of functions and classes for a specific purpose or utility along with the complied code and sample data. Dart comes with a rich set of default packages, loaded automatically when Dart console is started. However, any other package other than the default need to be installed and loaded explicitly first in order to use it. Once a packages is loaded, it can be used throughout the Dart environment.

Dart Package Manager

Dart comes with an inbuilt Package Manager known as pub package manager. It is used to install, organize and manage third-party libraries, tools and dependencies. Every Dart application has a pubspec.yaml file that keeps track of all the third-party libraries and application dependencies along with the metadata of applications like application name, author, version, and description. Most of the Dart IDEs offer in-built support for using pub that includes creating, downloading, updating, and publishing packages. Otherwise, you can use pub on the command line. Below is a list of the important pub commands

Sr.No Description
pub get This will get all packages your application is dependent upon.
pub upgrade This will upgrade all your application dependencies to latest version.
pub build This is used to create a built of your web application and it will create a build folder, with all related scripts in it.
pub help This command is used to know about all different pub commands.

Installing a Package

Step 1:- Add the package name in dependencies section of your project’s pubspec.yaml file. Then, you can run following command from the your application directory to get package installed in your project.

Recommended:-  Dart Assert Statement

This will download the packages under the packages folder in your application directory.


Here, we have added xml: to the project dependencies. This will install Dart XML package in the project.

Importing libraries from packages

Step 2:- Once the package is installed in our project, we need to import the required libraries from the package in our program as follows –


In this tutorial we have learn about the Dart Packages and its application with practical example. I hope you will like this tutorial.