How to Install Packages in Flutter?
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.
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.
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.
Now paste this under the “dependencies” in your pubspec.ymal file.
Note: Maintain the indentation while pasting..
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.
Step 3: Importing the Package
Again go to the page in Pub.dev and copy the import statement in the Installing Tab.
Paste this in the header of your dart file.
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.
Please Login to comment...