Dart 2 Updates

This page has information about changes in Dart 2, and how you can migrate your code from Dart 1.x and older 2.0.0-dev releases.

Migration tips: Flutter

See the detailed instructions on the Flutter Wiki.

Migration tips: web

If you develop for the web, you can start migrating to Dart 2 now:

Convert your code to be strong mode compliant.
For more information, see Strong mode and static typing, below.
Optimize the structure of your libraries.
Place library code that won’t be directly imported by your web code, or by other packages, under lib/src. For more information, see the documentation for creating library packages. You can find examples of this directory structure in the Stagehand templates.

Migration tips: servers and command-line scripts

If you develop servers or command-line scripts, you can start migrating to Dart 2 now:

Convert your code to be strong mode compliant.
For more information, see Strong mode and static typing, below.

Migration tips: packages

As a package owner, you need to do the following:

  • Follow the migration tips for the platforms that your package supports (see above).
  • Make sure your package’s users know how to report issues.
  • Respond quickly to issue reports.
  • If code changes aren’t backward compatible, update the lower SDK constraint.

Changes and backward compatibility

If you have to change your package’s code, try to make it work in 1.x, as well as Dart 2. For example, you might be able to add type annotations or (if an API has been removed) to use an alternative 1.x API.

If a backward-compatible change isn’t possible, update the lower SDK constraint.

Test your changes to make sure that your package works as expected.

Upper constraints on the SDK version

Don’t update an already-published package solely to indicate that it can be used with Dart 2 pre-releases. As long as a package has either no SDK constraints or an upper constraint of <2.0.0, pub get and similar pub commands in any Dart 2 pre-release can download the package. (The package won’t be usable with Dart 2 stable releases, but you can fix that later.)

When you update an existing package or publish a new one, specify an upper constraint of <2.0.0 for the SDK version. Examples:

# Works in 1.20.1+; might work in 2.0.0-dev:
sdk: '>=1.20.1 <2.0.0'

# Backward incompatible change requires at least 2.0.0-dev.1.2:
sdk: '>=2.0.0-dev.1.2 <2.0.0'

Eventually, you’ll need to publish new versions of your packages to declare Dart 2 compatibility, most likely using a <3.0.0 SDK constraint. Because incompatible changes might occur in any Dart 2 pre-release, don’t declare Dart 2 compatibility until we announce that it’s safe to do so.


If you publish packages, get ready for Dart 2:

  • Make it easy for users to report issues.
  • Respond quickly to issues.
  • Avoid unnecessary incompatibility.
  • Specify the correct SDK constraints.
  • Test your packages.

Testing with Dart 2 pre-releases

To test your code with Dart 2, you can use a pre-release of the Dart 2 SDK.

When running pub get, pub upgrade, or other pub commands from a Dart 2 pre-release, you might get packages that haven’t been verified to work with Dart 2. If you find a package that has Dart 2 issues, please report those issues immediately to the package maintainer, and let the Dart community know about any workarounds you find.

Obsolete features

The following features are redundant and won’t be in Dart 2:

Checked mode
Strong mode replaces checked mode. To learn how they differ, see What is the difference between strong mode and checked mode?
The dartdevc compiler performs fast compiles to JavaScript, thanks to strong mode. Instead of Dartium, you’ll use Chrome or other standard browsers for testing. For information on Dartium’s removal, see A stronger Dart for everyone.

Strong mode and static typing

In Dart 1.x, types are optional. You can remove all type annotations from a Dart 1.x program without affecting its behavior.

In Dart 2, types are mandatory, but type annotations are still optional. When a type annotation is absent, tools infer the type. With both static and runtime type checks, Dart 2 has a sound type system. This type system enables better tooling, as well as clearer, earlier feedback when you write code.

You can prepare for Dart 2 by using Dart 1.x with strong mode.

Migrate your code to strong mode, and you may identify some lurking bugs that are now more easily identifiable and addressable. You’ll also find it much easier to transition to Dart 2. For more information, see A stronger Dart for everyone and Strong Mode Dart.

To use strong mode in Dart 1.x, you must enable it. Note that runtime checks are not yet available unless you are developing for the web and using dartdevc.