Skip to content
Related Articles

Related Articles

Dart – Basics of Packages

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 15 Jul, 2020

The package is a set of dart program organized in an independent, reusable unit. It contains a set of functions and classes for a specific purpose or utility along with the compiled code and sample data. Dart comes with a rich set of default packages, loaded automatically when Dart console is started. Any other package other than the default needs 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 a pub that includes creating, downloading, updating, and publishing packages. Otherwise, pub ca be used on the command line. Below is a list of the important pub commands

list of the important pub commands

Installing a Package

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

pub get

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


An application needs to parse XML. Dart XML is a lightweight library that is open source and stable for parsing, traversing, querying, and building XML documents.


name: GFGapp
version: 0.0.1 
description: A simple core application. 
#  foo_bar: '>=1.0.0 <2.0.0' 

To refer to the dart XML in the project. The syntax is as follows:

import 'package:xml/xml.dart' as xml;

Read XML String

XML string can read and verify the input, Dart XML uses a parse() method.

Syntax: xml.parse(String input):


Parsing XML String Input. The following example shows how to parse XML string input.


// Dart program to illustrate 
// parsing XML in Dart
import 'package:xml/xml.dart' as xml; 
void main(){ 
   var bookshelfXml = '''


<?xml version = "1.0"?><bookshelf>  
     <title lang = "english">Growing a Language</title>  

     <title lang = "english">Learning XML</title>  

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!