Open In App

How to Install Packages in Flutter?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will look into the process of installing packages in flutter. Before we start incorporating a package, first let’s understand briefly what are Flutter Packages.

Flutter packages are open source libraries of code written and maintained by someone else, which we can incorporate in our project to maximize our efficiency and minimize our efforts. The whole process of installing a Flutter package can be broken down into 3 main steps.

Installing Flutter Packages:

Follow the below steps to install flutter packages:

Step 1: Finding the Package.

First of all head over to Pub.dev, where you can find all the flutter compatible packages. Now, if you already know which package you need to install, directly search the name of the Package in the search box. But if you don’t know exactly which package to install, search the keyword in the search box. Now, we need to find the appropriate package which not only meets our requirements but is also popular and well maintained.

We know this by looking into the score displayed on the right of the package name.

The score of a Package

We can also look in the Readme section of that package to know about the work the package can do. If you’re still confused head over to the article on Top Ten Flutter Packages by GeeksForGeeks.

Step 2: Installing the Package

Now that we have found our desire package, go to the Installing tab of that package.

Tabs in a package in Pub.dev

There are many ways to install a package but the most common and easy way is by adding it to your project’s pubspec file. Simply copy the code written under dependencies and go to your project’s pubspec.ymal file.

code for pubspec.ymal

Now paste this under the “dependencies” in your pubspec.ymal file.

Note: Maintain the indentation while pasting..

Dependencies

Now to finally install it enter the command in terminal flutter pub get and hit enter. Or if you are using Android studio just click on Packages get in the top right corner.

Android Studio options

Step 3: Importing the Package

Again go to the page in Pub.dev and copy the import statement in the Installing Tab.

Import statement

Paste this in the header of your dart file.

Import

Now we can use the functions/widgets provided by the package.

Note: Sometimes you might need to stop and restart the app for it to work properly.

If you want to know more about the package read the Readme and Examples tab of the package in Pub.dev, usually, the authors of the package explain all the things in the documentation. They also provide sample code in the Example tab, also you can see the score of that package in the Score tab.

For more information on how to use packages and installing head over to Flutter’s Documentation. For more articles on Flutter stay tuned on GeeksForGeeks.


Last Updated : 13 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads