My challenges until release my first dart package at pub.dev and how you can make it too

matteuus

Mateus Daniel

Posted on February 10, 2023

My challenges until release my first dart package at pub.dev and how you can make it too

As part of a Flutter developer routine, in my last four years I was very familiar with widgets components to make the UI, and some business logic of course, so now I've decided to dive into some pure dart code and maybe learn something different this time.

Reason and the path

Sometimes I used to do some projects using only dart since I want to automatize little tasks in my day as a programmer, in my job I act as a Tech Lead, and one of my main tasks is to standardize the workflow of mobile developers, setting best practices and also architectural models. To reach all of them the first thing was to make use of a pattern to make commits more understandable, to reach this objective we use the conventional commits, with that we easily make the message commits work as we want, in this article I will focus on that point, so to grant that the commits will be sent with this pattern I've decided to create a little dart project to make it.

After working on that for a while I've finally published it at pub.dev you can check here: git_helper, but that's not all, as part of this article I show the basics starting from creating a dart project until publishing it.

Get started

Consider that you already have the dart on your O.S, if not, download it from Dart SDK, with that configured you can check if everything is set up with the command dart --version, if this return a dart version so you have successfully install it on your computer.

With that configured let's create a new dart project with the command dart create my_project where my_project is your project name, so you can give any name that you want, if you are a flutter developer can notice that the project structure is a little bit different, the main folders are:

  • bin: where you have your code entry point with the main() function.
  • lib: here you can write all your logic code that makes things happen.
  • test: this folder, as the name said, it's used to put all your test codes, to test then just type dart test

After you write your code, you can start the process to publish it, there are some important points to notice here, the main one says that once you publish you can't delete, cause may impact if someone is using it, to make things happen we can use the command dart pub publish --dry-run, with that we can see a report of what's missing to start the publication, the major points are:

  • pubspec.yaml: in this file, you should declare some points like the name, version, description, and platforms, you can take this as an example:
name: my_project
version: 1.0.0

description: A simple dart project
repository: https://github.com/your_name/your_repository

environment:
  sdk: '>=2.18.6 <3.0.0'

dev_dependencies:
  test: ^1.16.0

dependencies:
  interact: ^2.1.1

executables: 
  my_project: 

platforms:
  linux:
  macos: 
  windows: 

Enter fullscreen mode Exit fullscreen mode
  • README.md: in this markdown file you should give instructions on how to use your project, here try to cover all that your code does.

  • CHANGELOG.md: this is also a markdown file, every version that will be published should be described here with your changes, you can take this as an example:

## 1.0.0

- My first project release.
- Implement my amazing feature

Enter fullscreen mode Exit fullscreen mode

and the last one, but also very important is the license, probably your project doesn't have this file by default, which means you should know what kind of license you want to use for the project, there are many types like GPL, MIT, and BSD each one has your own rules, like an open source project, I will give an example using the MIT license:

The MIT License (MIT)

Copyright (c) [year] [full name of copyright owner]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Enter fullscreen mode Exit fullscreen mode

is strongly important that you know what your license grant and why you opted for it.

Publishing

After all these steps, is finally time to publish your dart code as a package, to do that is more simple than all the processes before, but first, you should have an account on the platform, to make sure just go pub.dev and click on sign in button, now it's time to make the magic happen, just type dart pub publish, if is your first time the terminal, will appear a link to authenticate with you user, after that, all the upload process will be done automatically and that's it, just pay attention that your project will be revised, this process could take a while, in my case 30 minutes, after that, you have your package on pub.dev and ready to share with anyone in the world :).

Considerations

Since I've planned to create this git helper project and share it on pub.dev to help me and my teammates, you could have many opportunities to make something cool that could help someone, with all that said, really hope you have understood and enjoyed this journey, see you next time.

My final project is the git_helper, you can download my package and try it, if you want to improve, PRs are always welcome.

💖 💪 🙅 🚩
matteuus
Mateus Daniel

Posted on February 10, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related