Dart
Published in

Dart

Announcing Dart 2.14

Apple Silicon support, and improved productivity with default lints, better tools, and new language features

An illustration with text that summarizes the new 2.14 features

Apple Silicon support in the Dart SDK

Since Apple announced their new Apple Silicon processors in late 2020, we’ve worked on updating the Dart SDK to add support for native execution on the new processors. The needed changes have been available in the dev channel for a while, in the beta channel for the past month, and as of Dart 2.14.1 are now available in the Dart stable channel. When you download a macOS SDK, make sure to pick the ARM64 option. Note that the Dart SDK bundled in the Flutter SDK doesn’t have these improvements yet.

Standard lints shared for Dart and Flutter

Developers often prefer their code to follow a certain style. Many of these rules aren’t just stylistic preferences (like the well-known tabs vs. spaces discussion), but cover coding styles that are likely to lead to mistakes or introduce bugs. As an example, the Dart style guide requires using curly braces for all control flow structures, such as if-else statements. This prevents the classic dangling else problem, where there is ambiguity over how to interpret several nested if-else statements. Another example is type inference. While it’s fine to use type inference when declaring variables with initial values, it’s important to specify the type when declaring uninitialized variables, to ensure type safety.

  • package:lints/core.yaml: The main rules from the Dart style guide that we believe all Dart code should follow. The pub.dev scoring engine has been updated to use these instead of pedantic.
  • package:lints/recommended.yaml: The core rules, plus additional recommended rules. This set is recommended for all general Dart code.
  • package:flutter_lints/flutter.yaml: The core and recommended rules, plus additional Flutter-specific recommended rules. This set is recommended for all Flutter code.

Dart formatter and cascades

We made several optimizations to how the Dart formatter formats code with cascades. Before, the formatter would in some cases produce confusing formatting. For example, what is doIt() called on in this example?

var result = errorState ? foo : bad..doIt();
var result = errorState ? foo : bad
..doIt();

Pub support for ignoring files

Currently when you publish a package to the pub.dev community repository, pub grabs all the files in that folder with a few exceptions, skipping hidden files (those that begin with a dot: .) and files listed in .gitignore. Several developers have requested the ability to control which files are ignored outside of the list in .gitignore. For example, you might have some internal development tools in a tool/ folder that you use for maintaining your package, but that aren’t relevant to people who use your package.

Pub and `dart test` performance

While pub is perhaps most used for managing code dependencies, it also has a second important utility: powering tools. One such example is the Dart test tool, exposed via the dart test command. This command is really just a wrapper around the command pub run test:test, which runs the test entrypoint in package:test. Before invoking that entrypoint, pub first compiles it to native code that can be run faster.

$ dart test
Precompiling executable... (11.6s)
Precompiled test:test.
00:01 +1: All tests passed!

New language features

Dart 2.14 also contains a number of small language features. This time we focused on more specific improvements that are perhaps of more narrow utility, but enable more specialized use cases that weren’t previously supported.

late List<T Function<T>(T)> idFunctions;
var callback = [<T>(T value) => value];
late S Function<S extends T Function<T>(T)>(S) f;

Package and core library changes

We’ve made a number of enhancements to core Dart packages and libraries, including:

  • dart:core: Added static methods hash, hashAll, and hashAllUnordered to the Object class. These can be used to combine the hash codes of multiple objects in a consistent way (hashAll example).
  • dart:core: The native DateTime class now better handles local time around daylight saving time changes that aren’t precisely one hour — for example Lord Howe Island, Australia, which uses a 30-minute shift.
  • package:ffi: Added support for managing memory using an arena allocator (example). Arenas are a form of region-based memory management, where resources are automatically freed once the arena/region is exited.
  • package:ffigen: Now supports generating Dart typedefs from C typedefs.

Breaking changes

Dart 2.14 also contains a number of smaller, previously announced breaking changes. These changes are expected to impact just a few specialized use cases.

#46545: Removal of support for ECMAScript5

All modern browsers support recent ECMAScript versions, so two years ago we announced a plan to deprecate support for ECMAScript 5 (ES5). This enables us to leverage improvements in the latest ECMAScript and generate smaller output. In Dart 2.14 this work is complete, and the Dart web compilers no longer support ES5. As a result, older browsers — such as IE11 — are no longer supported.

#46100: Deprecation of stagehand, dartfmt, and dart2native

In the October 2020 Dart 2.10 blog post, we announced our work to combine all the Dart CLI developer tools into a single, combined dart tool (similar to the flutter tool). As part of that evolution, Dart 2.14 deprecated the former dartfmt and dart2native commands, and discontinued stagehand. These tools all have equivalent replacements in the unified dart tool.

#45451: Deprecation of VM Native Extensions

We’ve deprecated the Dart VM’s Native Extensions, our older mechanism for calling native code from Dart code. Dart FFI (foreign function interface) is our current mechanism for this use case, and we’re actively evolving that to be even more powerful and easy to use.

Null safety update

We launched sound null safety in March in the Dart 2.12 release. Null safety is Dart’s latest major productivity feature, intended to help you avoid null errors — a class of bugs that are often hard to spot.

2.14 availability and continued momentum

The enhanced Dart SDK containing the above changes is available today in the Dart 2.14.1 and Flutter 2.5 SDKs. We hope you’ll enjoy the new enhancements and features.

--

--

Dart is a client-optimized language for fast apps on any platform. Learn more at https://dart.dev.

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
Michael Thomsen

Product Manager working on Dart and Flutter. Helping developers is my passion!