Skip to main content

Step-by-Step Guide - how to use flutter packages ?

Step-by-Step Guide - how to use flutter packages ?

🗓️  Nov 29, 2019

Flutter packages allows us to quickly build apps without having to develop everything from scratch.

Where can I get flutter packages ?

Flutter packages - Dart pub

How can I add flutter packages to my project ?

step 1 : Add package name to pubspec.yaml file

  • Open pubspec.yaml file inside your project folder.
  • Under dependencies section, add your flutter package name and version info as a subsection.

In this demo we will use device_info package

Using Flutter Package
Using Flutter Package

step 2 : install your flutter package

Run “flutter pub get” command to install your flutter package from the command line.

  • Save the pubspec.yaml file and run “flutter pub get command” in terminal.
  • If using Android Studio - Save the file and Click “packages get” in action ribbon
  • If using VS Code : It automatically runs command on saving pubspec.yaml file.

step 3 : Add import statement to your app/main dart code.

import 'package:device_info/device_info.dart';
Import Package Code
Import Package Code

step 4 : Stop and Restart your App

Hot Reload and Hot Restart only updates the Dart code. If your packages uses and/or brings some platform-specific code(Java/Kotlin for Android, Swift/Objective-C for iOS) then a full restart might be required to avoid common missing plugin errors.

Now, we can access all the classes, methods and properties of the package. Thus we can use the package functionality in our project.

Bonus Tip : Check the package “Readme Tab” and “Example Tab” to learn how to use the package.

Also refer package documentation to deeply understand the package code and get started with the flutter package.

Frequently Asked Questions

You can find a wide variety of Flutter and Dart packages on the official package repository - https://pub.dev

Add the package name and version to the `dependencies` section of your `pubspec.yaml` file, and then run `flutter pub get`.

If a package contains native code (Java/Kotlin/Swift/Obj-C), perform a full stop and restart of your app instead of just using Hot Reload to ensure the plugin is correctly linked.

Most packages on pub.dev include a 'Readme' tab for an overview and an 'Example' tab for code snippets demonstrating how to implement the package.
Share This Post

Enjoyed this article?

Get notified when we publish new guides and tutorials. No spam, unsubscribe anytime.

📬 Newsletter coming soon — stay tuned!

The information contained on this blog is for academic and educational purposes only. Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. The materials (images, logos, content) contained in this web site are protected by applicable copyright and trademark law.