Skip to main content

New site for Dart news and articles

For the latest Dart news, visit our new blog at  https://medium.com/dartlang .

Dart 1.12 Released, with Null-Aware Operators and more

Dart 1.12.0 is now released! It contains the new null-aware operators language feature, and enhancements to pub, Observatory, dartdoc, and much more.

Null-aware operators

The new null-aware operators help you reduce the amount of code required to work with references that are potentially null. This feature is a collection of syntactic sugar for traversing (potentially null) object calls, conditionally setting a variable, and evaluating two (potentially null) expressions.

Click or tap the red Run button below to see them in action.

??

  if null operator. `expr1 ?? expr2` evaluates to `expr1` if not `null`, otherwise `expr2`.


??=

  null-aware assignment. `v ??= expr` causes `v` to be assigned `expr` only if `v` is `null`.


x?.p

  null-aware access. `x?.p` evaluates to `x.p` if `x` is not `null`, otherwise evaluates to `null`.


x?.m()
  
  null-aware method invocation. `x?.m()` invokes `m` only if `x` is not `null`.


Learn more about Dart's null-aware operators in our Language Tour.

.packages file

We continue in our efforts to eliminate symlinks by introducing the .packages file, which is a new way to specify where to find package dependencies. The pub package manager now writes a .packages file when getting or upgrading dependencies, and the VM and dartanalyzer use the .packages file for package resolution.

The Dart SDK still generates symlinks in 1.12, but the .packages file gets us closer to eliminating them. If you have tools that introspect packages, now is a good time to investigate the .packages file.

dartdoc

The dartdoc tool is a new way to generate beautiful, fast-loading API docs. It replaces dartdocgen, which we plan to remove from the SDK as soon as 1.13. dartdoc generates static docs, helps you search with find-as-you-type, and looks great on a mobile device.

dartfmt

Speed up your code reviews by automatically formatting your code. The dartfmt tool has been largely rewritten to support better handling for long argument lists, smarter indentation for cascades, nested functions, and collections, and fixes over 50 issues.

Observatory

Help identify memory leaks with Observatory's updated allocation profiler. Turn it on for a class, and track where instances of that class are created. Also new in 1.12 is support for dart:developer's log() function, which your app can use to stream log calls into Observatory's (or any connected debugger) console.

Stepping through async/await code has been significantly improved with Observatory's new anext command. You can now step over an await call, onto the next line of your code.

pub

The pub run commands can now toggle checked mode, with --checked. Pub now writes a .packages file when getting, upgrading, and globally activating your packages.

Lots more

The Dart SDK 1.12 CHANGELOG has lots more details about various API tweaks. We look forward to your feedback