how to use local flutter package in another flutter application?
Path dependency: A Flutter app can depend on a plugin via a file system path: dependency. The path can be either relative or absolute. For example, to depend on a plugin plugin1 located in a directory next to the app, use the following syntax:
dependencies:
plugin1:
path: ../your_package/
Find this file in your flutter application => pubspec.yaml
Use local dependency
dependencies:
flutter:
sdk: flutter
my_new_package:
path: ./my_new_package
Note: The ./my_new_package
above means that the my_new_package
directory containing the pubspec.yaml
for the package is a sub-directory of the app.
If you have the package as a directory at the same level as the app, in other words one level higher up in the directory tree, you can use ../my_new_package
(note the double dot) or a full path to the package directory.
For the full process:
Download the code for the plugin you want to use and place it at the "same" level as your flutter project directory
-- plugin-name -- your flutter directory -- lib -- android -- ios etc etc
Add the plugin path to pubspec.yaml. *If you are unsure of the correct plugin name to use, look at the
name:
attribute in the plugin's pubspec.yaml file. The plugin directory must also be saved with the samename:
dependencies: plugin-name: path: ../plugin-name
Run
Pub get
and you can import just like any other plugin. Only difference is when you click on any of the plugin classes during development, it will point to the local file.