Dart Packages

Dart package is the collection of a well-organized, independent, and reusable code unit. Applications might be needed to implement third-party libraries or packages. The package generally contains a set of classes, functions, or unit of code for specific tasks along with the compiled program and sample data.

Introduction

  • Dart provides an extensive set of default packages that load automatically when the dart console starts.

  • However, if we need packages other than the default packages then its need to installed and loaded explicitly in order to use.

  • When a package is loaded, it can be used in the whole Dart environment.

  • A package is a mechanism to encapsulate a group of programming units.

  • 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.

Dart Package Manager

  • Every language provides the functionality for handling the external packages such as Nuget for .NET, Gradle or Maven for Java, npm for Node.js, etc.

  • Dart has the inbuilt package manager, which is called a pub. It is basically used to organize, manage the third-party libraries, tools, dependencies, and also used to install the packages in the repository.

  • Every Dart application consists of a pubspec.yaml file which includes the metadata of the file. The metadata of the package holds the author, version, application name, and description.

  • The full form of the yaml is a Yet Another Markup Language.

  • The pubspec.yaml is used to download the various libraries that application needs during programming.

  • The pubspec.yaml file must look like as follows.

name: 'vector_victor'   
version: 0.0.1   
description: An absolute bare-bones web app.   
...   
dependencies: browser: '>=0.10.0 <0.11.0'   
  • The Dart IDE’s provides the inbuilt support for using the pub that consist of creating, downloading, updating, and publishing packages, Otherwise we can use the pub command line.

The following is the list of the few important pub commands.

CommandDescription
pub getIt is used to get all packages of application dependent on.
pub upgradeIt is used to upgrade all application dependencies to the modern version.
pub buildIt is used to construct your web application, and it will create a build folder, with all related scripts in it.
pub helpIt is used to get help related to all pub commands or when we stuck while programming.