Publishing a Flutter package with Travis CI

Roberto Huertas
Jan 20, 2019 · 3 min read
Image for post
Image for post

Are you’re thinking of building a Flutter package or have you already built one but you don’t know how to set Travis-CI up? If that’s the case, you’ve come to the right place!

Building a Flutter package

The best way to learn how to build your own Flutter package is reading the Flutter documentation. The process is pretty straightforward so I don’t think it’s worth it to replicate it here.

One of the important things to take into account is that all Flutter packages are rated depending on the quality of the package. This means that if you provide an Example you will get more points. But don’t worry, whenever you publish your package you will be presented with some information on how to improve this score.

Image for post
Image for post

Composing the Travis-CI configuration file

All you have to do is create a new file called .travis.yml in the root of your project and copy the content below:

Note that we’re only publishing our package whenever we create a new tag.

Publication script

Once you have your .travis.yml file ready and set up, you must create a publication script.

Let’s create a new folder called .travis and a file called publish.sh in it. Copy the script below:

As you can see, the publication script is expecting some environment variables. But, how do we get them?

Unfortunately, the only way to get this information is by publishing your package manually so you can authenticate and get all the necessary tokens.

This should be an easy one-time process so let’s do that!

First, let’s test that everything is working fine and let’s do a “fake publication” by executing:

pub publish --dry-run

If you see something wrong, fix it. If everything is fine then just:

pub publish

You will be immediately required to open your browser and authenticate with your Google credentials and once you authenticate, a new file will be available to you in your computer: ~/.pub-cache/credentials.json.

Open it and there you will find all the information you need to set up the Travis environment variables.

Image for post
Image for post

Things to take into account

There are a few things that I found out the hard way:

Trying it out

If you have completed all the steps, you’re project will be analyzed, tested and built without publishing every time you push to your git repository.

Whenever you’re ready to publish, just create and push a new tag and Travis will take care of it!

Of course, feel free to customize the scripts according to your needs.

Enjoy!


Originally published at robertohuertas.com on January 20, 2019.

Roberto Huertas

Rust, TypeScript, Flutter and others

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store