Add Packages To Your Flutter App

Add Packages To Your Flutter App

How to add external packages(libraries) to your flutter application to improve productivity

Aravind Chowdary
·Aug 27, 2022·

2 min read

Subscribe to our newsletter and never miss any upcoming articles

Play this article

Table of contents

  • Introduction
  • How To Add Packages From Flutter Pub
  • How To Add Flutter Packages From GitHub
  • How To Add Package From Local File System In Flutter

Introduction

To add a new package to a Flutter application, we need to add a reference to it as a dependency in the pubspec.yaml file. There are different ways to add packages to a Flutter application. Mainly, you can add a package from:

  • Flutter pub.dev (official Flutter package server)
  • GitHub
  • Local File System

How To Add Packages From Flutter Pub

Screenshot (2).png

  • Go to the official site (pub.dev) for Flutter packages and find the plugin that you want to install.
  • On the “Installing” tab you can find the complete instruction on how to install the plugin.
  • As shown in the image above, just copy and paste the dependency in your pubspec.yaml file. When you save the YAML file, it will automatically download the package into your machine.

How To Add Flutter Packages From GitHub

You can use any Flutter plugin/package from the Github server as long as you have access to that repository.

  • Get the URL for the remote repository.
  • Add a reference to the plugin repository in the pubspec file as below:
useful_service:
    git: https://github.com/xyz/useful_service.git
  • You can also specify a specific branch of the repository as well by specifying the branch name with ref keyword.
useful_service:
  git:
    url: https://github.com/xyz/useful_service.git
    ref: develop

How To Add Package From Local File System In Flutter

You can add a reference to a plugin/package directly from your local computer. Just be careful when you share the project with your team. Since the plugin is only on your computer, others will not be able to use the plugin when working on the same project.

  • Get the relative path to the folder where your plugin is located on your machine.
  • Use the path keyword to add a reference to this plugin.
my_local_package:
    path: ../packages/my_local_package/

Did you find this article valuable?

Support FlutterBlocks by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this