In this post we will look at the various ways for adding packages in Flutter application.
To add a new package to a Flutter application, we need to add a reference to it as a dependency in the
pubspec.yaml file. There are different ways to add packages in a Flutter application. Mainly, you can add a package from:
How To Add Packages From Flutter Pub
- Go to the official site (pub.dev) for Flutter packages and find the plugin that you want to install.
- On the “Installing” tab you can find the complete instruction on how to install the plugin.
- As shown on the image above, just copy and paste the dependency in your
- When you save the
yamlfile, it will automatically download the package into your machine.
How To Add Flutter Packages From GitHub
You can use any Flutter plugin/packages from Github server as long as you have access to that repository.
- Get the url for the remote repository.
- Add reference to the plugin repository in the
pubspecfile as below:
- You can also specify specific branch of the repository as well by specifying the branch name with
How To Add Package From Local File System In Flutter
You can add reference to a plugin/package directly from your local computer. Just be careful when you share the project with your team. Since the plugin is only in your computer, others will not be able to use the plugin when working on the same project.
- Get the relative path to the folder where your plugin is located in your machine.
- Use the
pathkeyword to add reference to this plugin.