In Flutter, you can install libraries (or packages) using pub.dev, the official package repository for Dart and Flutter.
Steps to Install a Library in Flutter
- Go to the Official Source
Visit https://pub.dev – this is the official source for Flutter libraries/packages.
-
Search for the Library
-
Use the search bar to find the package you need.
-
Example: Searching for
http
for handling HTTP requests.
-
-
Add the Library to
pubspec.yaml
In your Flutter project, open thepubspec.yaml
file and add the library underdependencies
:dependencies: flutter: sdk: flutter {exampleLibraryName}: ^version
⚠️ Note: Always check for the latest stable version on pub.dev.
-
Run
flutter pub get
In the terminal, navigate to your project directory and run:flutter pub get
This downloads the package and makes it available for use.
How to Check All Installed Libraries
To view all the libraries/packages installed in your project, check the pubspec.lock
file.
Commands for Package Management
Command | Usage |
---|---|
| Installs new dependencies from |
| Upgrades all packages to the latest compatible versions. |
| Automatically adds a package to |
| Lists outdated packages in your project. |
Best Practices
-
Use the latest stable version of a package from pub.dev.
-
Always add a version constraint to avoid breaking changes.
-
Regularly update packages using
flutter pub upgrade
.