Publishing a Flutter package with Travis CI

Roberto Huertas
Jan 20, 2019 · 3 min read

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.

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 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:

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

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.

Things to take into account

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

  1. If you provide an example folder make sure that you have a pubspec.yaml in it because otherwise flutter packages get command will fail. Make sure that everything works in this folder too before pushing any changes.
  2. Check that your script has execution permissions. If you don’t do this you will get a cryptic 127 error.
  3. pub get is called automatically by Travis when you select Dart as the default language. This will lead you to receive an error (it seems to be a known issue in Travis). The only way to get rid of it is to completely override the install step. This is already managed for you in our previous .travis.yml script.
  4. The publication tokens will eventually expire so we’ll have to reset the Travis environment variables when this happens (and hence do a manual publication again :( ).

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.


Originally published at on January 20, 2019.

Roberto Huertas

Rust, TypeScript, Flutter and others

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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