Search code examples
flutterflutter-plugin

How to use flutter plugin, that I created, in my flutter app as local plugin


I have created a flutter plugin for android and ios and I want to use that plugin in my flutter app locally. I don't want to upload it to pub.dev but to use it locally in my flutter app. I searched a bit and I found that I can use external packages locally but I didn't find anything about a plugin. These are directories under my plugin package all_pdf_tools:

enter image description here

Out of these which directory do I need to move to my flutter app directory and then how should I declare it to use it in my pubspec.yaml and then how can I use my plugin's methods in the flutter app.

Thank you.


Solution

  • Make sure that your Flutter app and plugin are in sibling folders.

    The add a dependency in pubspec.yaml of your Flutter app:

    dependencies:
      all_pdf_tools:
        path: ../all_pdf_tools
    

    This tells your Flutter project to look for your plugin at the relative path, rather than in pub or a local git repo.

    (If you look in all_pdf_tools/example/pubspec.yaml you'll see this is how the example app refers to its plugin by using path: ../)