Publish Your First Package on Pub.dev -Flutter

 

How to Create, Publish and Manage Flutter Packages and get 130 Point


In this article, we will go to learn how to create a new package and get all 130 points, follow all the steps carefully. 

1- First go to pub.dev 

In the search bar write the name you are about to give your package, we are doing this just to ensure if our desirable has not already been reserved.

Ok. seems great, this name is free to use.

2- Create a new flutter project and select Flutter Package:

Now open your IDE android studio or any other and select Flutter Package




Now it's time to give a name to your package. make sure to write the same name you have search in pub.dev. Because whatever name you give to your package this time, your package will upload with that same name.


Great your package is created.

3- Start working on your package. 



The green arrow is the file where you will write your code, great. But what that red question mark indicates? Why main.dart file doesn't show in that place? Don't worry! Packages don't have the main file but if we want to test how our package works we can test it and the plus is here that if we add the testing file here it will give us an extra point. I will show you how to add the main file later in this tutorial. 


I have written my code now it's time to set other classes.

4- pubspec.yaml.


Let's edit pubspec.yaml file.



1. name: write the name of your package.
2. description: you can write a brief description of the package and what the package does.
3. version: must be 0.0.1. 
4. author: remove the author tag from here.
5. homepage: you need to enter the package repository URLLet's learn what to do that.

5- Create Repo on GitHub.

As we need to push our code on the GitHub repo before uploading a package so Let's create a repo



Write the name of your repo, make it public, create it.


Once your repo is created copy the URL mentioned with a green border. Don't close this tab because we will follow the steps written in a yellow box but for now, just copy the URL and paste it to the homepage, let me show you how.



as you can see I have removed the author tag from here and add the URL.

6- README.md.

Document your package. Write about what it does, how to use it, add a .gif or screenshot if you can, and overall, just try to explain how to use your package. You can also check a demo from my repo readme.md.

7- LICENSE.md

Choose a license for your package. I used the MIT license for my package hereYou find something suitable on choosealicense.com.

8- CHANGELOG.md

In this file, you should list down the changes you make with each version of your package. Demo


9- Write an example.

As we have done creating Readme and Changelog files now it's time to create an Example. And as I promised you to get all 130 points so by adding example it will increase 10 points. 


Step#1: 


Create a new flutter project named it "example" don't write any other name and put this project in your package directory as shown below 


This is the example project you've just created and now it shows the main file in the yellow box means you can test your package. Write appropriate code in this main file. Demo

Step#2: 



open example/pubspec.yaml file and write the code as mentioned in an orange box (replace package name with yours). run the code and check if everything is working perfectly, fix if any error or bug found.


9- Format your code.

Add comments and format your code will add 30 points so let's do it.
Add comments: add all necessary comments using "///" Demo
Format your code: write "dart format ." in the terminal, it will format all your files.

10- Push code to Github Repo

Go back to step#5, open your repo tab and copy and paste the lines one by one in your Android terminal. Now go to your repo and check if all files pushed successfully?

10- Publish Package

Step#1:  Prior to publishing, make sure to review the pubspec.yamlREADME.md, and CHANGELOG.md files to make sure their content is complete and correct.

Step#2: Next, Before publishing the package check if our code is error-free? run this line in terminal

"flutter packages pub publish --dry-run"

your output must be "Package has 0 warnings."

Step#3: Go to pub.dev and sign in with your account.

Step#4:  Now as we are ready, write this line in terminal

"flutter packages pub publish". 

then it will ask you "Do you want to publish your_package_name 0.0.1 (y/N)? "
type "y" here.

output will be like  "Successfully uploaded package."

Hurrah we did it 😍😍😍

- There is a treat for you if you want to upload your package with your verified account follow this link

if you like this article? please support me by like my work










Comments