Mastering Flutter: Publish your package to pub.dev

You’ve written a beautiful dart package or plugin and you want to share it to the world? You’re in the right place, in this tutorial we will run through the steps that you need to make to publish your app on pub.dev.

Your best friend: pubspec.yaml

The main file that you will have to touch is the pubspec.yml file, here you will have to write all the informations about the package that will appear on pub.dev. Here you can find the complete specification for all the possible fields of the pubspec, but let’s have a look at the most important ones.

The file can be divided in 3 main parts:

  • The metadata
  • The environment
  • The dependencies

Metadata

The first part is composed of metadata of the package that will appear in the page of the package on pub.dev. Here you can find:

  • name: the name of the package.
  • description: a short description of the package (60 to 180 characters).
  • version: the version of the package that you’re publishing.
  • homepage: a website pointing to the homepage of your package, it can be your website of the website that describes this plugin.
  • repository: the url of the repository of your package, in this way users can contribute to your package or open issues if they find problems using your package.

Environment

Here you can define the range of the versions of Flutter that your package supports. This is particularly useful if your package uses a feature that’s included in version (e.g. null-safety).

Dependencies

Here you will need to define all the packages that your package depends on. This section should already be filled, make sure to use only packages that are hosted on pub.dev.

Prepare to publish

Before publishing make sure to have the following things:

  • In the main folder of your package there’s a README.md file with a presentation of your package and all the instructions that the users will need.
  • LICENSE file with the license that you have choose. The Flutter team recommends the BSD 3-clause license which is the one that they typically use but you can choose to use a more strict or a more light license.
  • To publish the package you will need a Google account, make one if don’t have one yet. The email of the Google account will be displayed in the pub.dev page, in the author section, unless you publish with a verified publisher.
  • To obtain a great score in the “Pass static analysis” section, make sure that your code is correctly  formatted and indented.
    You can use the dartfmt command to automatically format your files. E.g. if you run this command all the files in the current directory will be formatted: dartfmt -w .
  • Make sure that your code is documented in the best way possible, following those guidelines.
  • Compile the content of the CHANGELOG.md file, if it’s the first time that you’re publishing your package use a simple description such as “First app release”.

Publish your package

You’re ready to publish your package, run the following command to check if everything is correct:

$ flutter pub publish --dry-run

If the commend doesn’t give you warnings or errors you can publish your package; make sure that everything is in place because publishing is forever

$ flutter pub publish

Update your package

When you will need to update your package the commands that you’ll need to update your package you will use the same command (flutter pub publish). Here’s a small checklist of things to do before publishing an update:

  • Update the version of the package in the pubspec.yaml file.
  • Update the CHANGELOG.md file with the correct version and changes.
  • Run the dartfmt command to check that everything is formatted properly.
  • Run a flutter pub publish --dry-run to check if there are any warnings or errors.

Publish as a verified publisher

If you want to give your package a more professional look you can become a verified publisher. The verification process is based on DNS verification, you can find more info on the official page on pub.dev.

Becoming a verified publisher you will not be displayed with your email in the authors section on pub.dev but your package will be published with the website together with the verified badge. It will be also easier to manage access and authorizations to other users.

Here’s an example of a package published with a verified publisher.

Add a Comment

Your email address will not be published. Required fields are marked *