Updating your pub package to Dart 2

Take inventory

Decide which ones are worth updating

These are all mine, and I’m happy for these to keep those scores.
You get to this visualization by clicking the last tab — the one that has the score in a circle.

Install Dart 2 (and 1)

alias dart1=/path/to/dart-1.24.3-sdk/bin/dart
alias dartanalyzer1=/path/to/dart-1.24.3-sdk/bin/dartanalyzer
alias pub1=/path/to/dart-1.24.3-sdk/bin/pub
$ dart --version
Dart VM version: 2.0.0-dev.69.1 (Fri Jul 20 18:30:52 2018 +0200) on "macos_x64"
$ dart1 --version
Dart VM version: 1.24.3 (Wed Dec 13 23:26:59 2017) on "macos_x64"

Migrate the code

  • Add .dart_tool/ into .gitignore
  • Bump the SDK version constraints in pubspec.yaml from something like sdk: ">=1.8.0 <2.0.0" to something like sdk: ">=2.0.0-dev <3.0.0" (or sdk: ">=1.24.3 <3.0.0" if you want to keep Dart 1 compatibility)
  • Bump all dependencies (and dev_dependencies) in pubspec.yaml to Dart-2-compatible versions (check their change log to find the version). Avoid pinning dependencies to the very latest version unless you absolutely need to. Having a broader range will give you package users more freedom to pick their own dependency versions.
  • Run pub upgrade (not just pub get). Even better, run _PUB_TEST_SDK_VERSION=2.0.0 pub upgrade (explained here).

Optional: add CI testing

language: dart
dart:
- dev
script:
- dartanalyzer --fatal-warnings --fatal-lints .
- pub run test

Add a change log

## 1.2.3

- Upgrade to Dart 2

Bump your own version

Upload to pub

--

--

--

Developer and manager working on Google’s Dart programming language and Flutter SDK; gamebooks enthusiast; https://filiph.net

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Medical Billing Software Market Size | Analysis, Segments, Top Key Players, Drivers and Trends to…

How I got my first freelancing project!

Magic Commands for Profiling in Jupyter Notebook

Use Clean Code to Pass Your System Design Interview

ArcGIS Pro Python Clone Error, CondaVerification Error, Environments Clone Error solved!

Control, Responsibility, and Delegation in DevOps

The Fun cron Tutorial

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
Filip Hracek

Filip Hracek

Developer and manager working on Google’s Dart programming language and Flutter SDK; gamebooks enthusiast; https://filiph.net

More from Medium

Get Flutter text layout super powers with Super Text Layout

Your First Real Flutter Unit Tests

A Dart File Server in 10 lines

Understanding Default Flutter Project Structure