Dart language evolution

This page lists notable changes and additions to the Dart programming language. If you want details about the currently supported language, see the language tour or the language specification.

For a peek into current features being discussed, investigated, and added to the Dart language, see the language funnel tracker in the Dart language GitHub repo.

Dart 2.0

Dart 2.0 implemented a new sound type system. Before Dart 2.0, types weren’t fully sound, and Dart relied heavily on runtime type checking. Dart 1.x code had to be migrated to Dart 2.

Dart 2.1

Dart 2.1 added support for int-to-double conversion, allowing developers to set double values using integer literals. This feature removed the annoyance of being forced to use a double literal (for example, 4.0) when the value was conceptually an integer. In the following Flutter code, horizontal and vertical have type double:

  1. padding: const EdgeInsets.symmetric(
  2. horizontal: 4,
  3. vertical: 8,
  4. )

Dart 2.2

Dart has always supported literal lists and maps, but Dart 2.2 added support for set literals:

  1. const Set<String> currencies = {'EUR', 'USD', 'JPY'};

Dart 2.3

Dart 2.3 added three operators designed to improve code that performs list manipulation, such as declarative UI code.

The spread operator enables unpacking the elements from one list into another. In the following example, the list returned by buildMainElements() is unpacked into the list being passed to the children argument:

  1. Widget build(BuildContext context) {
  2. return Column(children: [
  3. Header(),
  4. ...buildMainElements(),
  5. Footer(),
  6. ]);
  7. }

The collection if operator enables adding elements conditionally. The following example adds a FlatButton element unless this is the last page:

  1. Widget build(BuildContext context) {
  2. return Column(children: [
  3. Text(mainText),
  4. if (page != pages.last)
  5. FlatButton(child: Text('Next')),
  6. ]);
  7. }

The collection for operator enables building repeated elements. The following example adds one HeadingAction element for each section in sections:

  1. Widget build(BuildContext context) {
  2. return Column(children: [
  3. Text(mainText),
  4. for (var section in sections)
  5. HeadingAction(section.heading),
  6. ]);
  7. }

Dart 2.5

Dart 2.5 didn’t add any features to the Dart language, but it did add support for calling native C code from Dart code using a new core library, dart:ffi.

Dart 2.6

Dart 2.6 didn’t add any features to the Dart language, but it did add a new tool, dart2native, for compiling Dart code to native executables.

Dart 2.7

Dart 2.7 added support for extension methods, enabling you to add functionality to any type — even types you don’t control — with the brevity and auto-complete experience of regular method calls.

The following example extends the String class from dart:core with a new parseInt() method:

  1. extension ParseNumbers on String {
  2. int parseInt() {
  3. return int.parse(this);
  4. }
  5. }
  6. void main() {
  7. int i = '42'.parseInt();
  8. print(i);
  9. }

Dart 2.8

Dart 2.8 didn’t add any features to the Dart language, but it did contain a number of preparatory breaking changes to ensure great nullability-related usability and performance in the upcoming null safety feature.

It also contained a faster pub tool, and a new pub outdated command.