Skip to main content

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

In this guide  we will learn how to use flutter packages in our flutter projects. Using flutter packages we can enhance our app functionality by reusing code written by the flutter team or flutter community. Flutter packages allows us to quickly build apps without having to develop everything from scratch.

Using Flutter Packages

Where can I get flutter packages ?

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.

To learn more about flutter - Flutter Developer Guide

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.

Flutter, Android and the Android logo are registered trademarks of Google LLC.

Popular posts from this blog

Step-by-Step Guide to create a new flutter project using Visual Studio Code [VS Code]

This is a beginner's guide to visual studio code and flutter. VS Code is a light weight editor with flutter app development, execution and debug support. Visual Studio Code is a source-code editor developed by Microsoft. Install latest stable version of VS Code Install the Flutter and Dart plugins In VS Code "Extensions" Tab, search field type flutter, select "Flutter" in the list and click "Install". Flutter plugin also installs the required Dart plugin. Validate your flutter setup using "flutter doctor command". Once Flutter SDK and your VS Code Editor is up and running, Flutter Visual Studio Code To Create a new flutter project from the flutter starter app template follow the below steps step 1 : Open Command Palette Use Shortcut key - Ctrl+Shift+P or Cmd+Shift+P on macOS OR Go to View Menu, select "Command Palette" VS Code Command Palette step 2 : Create Flutter New Project Sele

Step-by-Step Guide for Flutter Android APK Signing and Release

In this guide we will learn how to sign the release version of apk or aab(android app bundle) to publish our flutter app to android play store. flutter release apk How to sign the apk or app bundle created using flutter ? To publish your app on Play Store, you need to give your app a digital signature. step 1 : Create a new keystore file ; if you have an existing keystore , skip this step Run command in your terminal for linux/mac keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key On Windows, use the following command: keytool -genkey -v -keystore c:/Users/USER_NAME/key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key Fill in the required info inside the terminal Enter keystore password: test@12345 Re-enter new password: test@12345 What is your first and last name? [test]: test What is the name of your organizational unit? [test]: test

Step-by-Step Guide to take a App Screenshot with the Device Frame using Android Studio

This guide will help you to take a screenshot with the device frame using android studio. If we capture screenshot using the default android emulator "Capture Screenshot" option, then screenshot will not have the device frame. Android Emulator - Screen Capture By using android studio we can capture screenshot with different devices frame. How to take a App Screenshot with the Device Frame using Android Studio step 1 : Load your project in android studio and run the app Open Android Studio Load your android app project in android studio.  Build and Run your app using android emulator or a connected physical device.  If you are using a physical device make sure that you have enabled USB DEBUGGING option. Android Studio - Load Project step 2 : Open Logcat in Android Studio Check out bottom left corner in android studio to find Logcat option and click to open Logcat If it is not visible then select "View Menu" and search for