How to create flutter package for pub.dev

Hi, folks how are you all, so, in this article, we are about to learn how to create a flutter package. In this article we only see the basic step that we have to do to create a package, we will use the default code.

let’s start first we have to create a flutter package using an android studio but if you want to create it using the command line use this command.

Step 1:-

flutter create — template=package package_name

OR

Give your package name and description.

Step 2:-

Create a git repository and upload your package into git.

git init
git add — all
git commit -m “initial commit”
git remote add origin
https://github.com/your git link
git push -u origin master

Your file structure is something looks like this.

In lib -> you have to write your package code.

In test -> you can write the test cases.

CHANGELOG.md -> you can write the changes with date and description.

LICENSE -> you write your license.

pubspec.yaml -> you can write your project description and import assets, etc.

CHANGELOG.md

## [version] - Date* explanations about changes.

LICENSE

I am choosing an open-source MIT LICENSE.

MIT License

Copyright (c) [2020][Osama Asif]

write your name in the license.

Step 3:-

Now come to the code section.

As I told you I am using a sample code to show you how to create a flutter package. You can write your code as per your requirement.

Step 4:-

PUBLISH PACKAGE

Before publishing the package push your code to the git repository.

for a dry run, your package uses the below command.

flutter pub publish --dry-run

use the below command to publish the package into pub.dev

NOTE: -

The next step is publishing to pub.dev, but be sure that you are ready because publishing is forever:

flutter packages pub publish

Hurray…!!!

now we know how to create and publish a flutter package.

find out more articles.

Senior Software engineer, working on Flutter for more than 3 years, public speaker, article writer, and also an open-source contributor.