Published in


Creating local package in flutter

In this article we will discuss about how to create local/internal package that can be used within the same flutter project.

  1. To create a local package for the flutter project we need to create a separate directory called “packages” inside the root directory of the main flutter project.

2. Now open the project in terminal and move inside the above created packages folder. After doing so, run the following cmd in the terminal.

flutter create --template=package <package name>

You can replace the <package name> and specify any package name you want.

After this is done, we will be able to notice new files being created inside the above mentioned packages folder.

We can now delete the default calculator code present inside the lib/<package name>.dart file and write down our core logic of the package.

In our case we will be creating a package that will wrap any flutter widget with a colored container.

child:Text("some text")


Now we need to modify the lib/<package name>.dart file with the below code.

Once this is done, in order to use this package inside the main project we need to add this package as a dependency inside the main project’s pubspec.yaml file.

In our case the package name is coloredcontainer therefore we need to specify them and provide the relative path of the package from your root directory.

That’s it, now we can use the widgets specified inside this package (ColoredContainer widget in our case) in the main project by importing them.

Well that’s it. 🥳🎉

This is how we can create local packages in our flutter apps.

Get the complete source code here 👉:

If you found this article useful and wish to support my work, you can consider buying me a coffee.👇



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vijay R

Vijay R


Hai👋 I’m a flutter developer experienced in designing and developing stunning mobile apps. Reach out for freelance projects: