Create your own dart package in flutter 2022
In this article we will learn- how to create own dart package, and publish it for the community.
Table of contents:
- Difference between package and plugin
- Create project for package
- Add your functional code
- Check for any warning/error
- Update the necessary files for good documentation
- Add license
- Publish to pub.dev
- Difference between package and plugin
The main difference between package and plugin-
Package: A “package” contains only Dart code.
Plugin: A “plugin” contains both Dart and Native code (kotlin/js/swift/…)
2. Create project for package
Create a new flutter project and select flutter package.
You can go through the official website for the proper documentation-
3. Add your functional code
You need to export the file which is responsible for the code and functionality. Write your code inside the exported file.
4. Check for any warning/error
Run this command to check for any warning/error. If it’s showing 0 warning/error, you are good to go.
dart pub publish — dry-run
5. Update the necessary files for good documentation
You need to update pubspec.yaml file with the repository of codes (May use github) and pass the link of repository in homepage: (Like below image)-
After that, we need to update README.md and CHANGELOG.md files with proper documentation-
You can share some code segment if you feel required.
6. Add License
Add license for the package, you can search how to add a license on google.
7. Publish to pub.dev
Now, We are all set to launch the new package to pub.dev-
Let’s run the publish command in terminal-
dart pub publish
Now, When you fire this command for the first time then it will generate a URL and ask for the authentication. You just have to copy the URL from console and paste it on browser, then it will show authentication successful. And will be uploaded on pub.dev with this beautiful message.
Thanks for your time, Hit the clap if you like the content.
Please support me, If you really want. Thanks.
Some more blogs written for flutter developers, Please have a look into it.