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.
📺 Video Tutorial
- 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.
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
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 👉: https://github.com/vijayinyoutube/colored_container_local_package
If you found this article useful and wish to support my work, you can consider buying me a coffee.👇
Check out all my Flutter related blogs here.,👇
Other articles you may like.,
Shared Preferences in Flutter
Store the data locally in Flutter app using Shared Preferences.
Setting up your Flutter app for publishing in Play Store.
Before publishing our Flutter app in Google Play Store we need to brush up few feature to make sure that the app is…
Creating Desktop Apps using Flutter
In this article we will discuss about how to create and run a desktop app using Flutter.
If you want to know more about Flutter and various Widgets in Flutter…?🤓 Then visit my channel 👉🏻 vijaycreations🚩