Importing packages or plugins are very important in flutter app development. That makes easy the development, so save lot of line of codes and time.
What is a Flutter Package?
These are the shared contributions on internet. You can use those codes on your apps as packages instead of writing for some features from scratch.
How to Find Flutter Packages ?
pub.dev is the official site for Flutter packages. There you can search and find packages for your purposes. You can also find packages on different forums and web sites.
How to Import a Package?
On your flutter project directory, there should be a file named ‘pubspec.yaml’. See the screenshot from ‘Android Studio’.
Open the file.
You need to note four things
1. Place where do we specify the package name.
You can place the package under dependencies.
There must be 2 spaces from left side.
3. Package name
Package name must be same as the package server and case sensitive. Where flutter_laucher_icons is just an example.
4. Package version.
You can specify the exact version like 0.9.0 or version with same number or higher using character ^ (example: package_name : ^0.9.0). You may also import any version using the keyword ‘any‘ (example: package_name : any)
5. Pub get
Now you need to download the package from the pub.dev site using the command ‘flutter pub get’ on Terminal or click on ‘pub get‘ link on top right of the ‘pubspec.yaml’ page (in android studio).
Using the Flutter Package
If you want to use this package on a dart file, then use the keyword on top of the page.
Some of packages does not used on screens, so you don’t need to import the package like above. Command line codes are enough to use the packages. See how the flutter_laucher_icons are used on the app for changing app icon into custom one.
Be First to Comment