Dart 2.1, an increment over Dart 2 is released with changes for performance and usability. New features in Dart 2.1 include smaller code size, faster type checks, better usability for type errors, and new language features to improve productivity.
Support for int-to-double conversion in Dart 2.1
Developers new to Flutter often face obstacles in the form of analysis errors when specifying padding, setting font sizes, etc. These errors make sense from a system point of view. For example, the API expects a type say, a double, and the developer specifies the value in a different type say, an int. From a usability point of view, it seems foolish as there is a trivial conversion from int to double. So, Dart 2.1 now infers the line where applicable and silently evaluates an int as a double.
Language support for mixins in Dart 2.1
Dart 2.1 comes with a new syntax for mixins. It features a new mixin keyword that can be used to define classes which can exclusively be used as mixins. Support is also added so that mixins can extend other classes and invoke methods in their superclass. Previously, mixins could only extend Object.
An example of extending non-Object classes is from Flutter’s animation APIs. The SingleTickerProviderStateMixin which is a framework class that provides a ticker for advancing an animation by a single frame declares a mixin that implements the general TickerProvider interface. The animations are applicable only to stateful widgets since the position in the animation is considered state. The new mixin support in Dart 2.1 allows expressing this by declaring that only classes that extend the Flutter State class can use the mixin.
Compile-time type checks
The type system in Dart 2 protects users during development, indicating violations of the contract specified by the types. Such checks at edit time were added in Dart 2 powered by the Dart Analyzer. There is another place where developers might expect type checks. Like compile time, when performing a Flutter release build. Such checks were incomplete in Dart 2, which potentially leading to usability issues where bad source code could compile without errors. In Dart 2.1, these checks are complete. Now, the Analyzer and Dart compiler both contain the same checks.
Performance improvements for Flutter developers
In a few cases, though, the comprehensive checks in Dart 2 caused undesirable overheads of 20–40%. Dart 2.1 has greatly reduced cost of type checks. This is applicable to both, AOT-compiled code and code run in the VM with JIT compilation.
The developer tools which run using the VM, benefit from this. Performing code analysis of one large benchmark app used to take about 41 seconds, it now takes only around 25 seconds.
Performance improvements for web developers
The code size and compile time is also improved for Dart code running on the web. The output size of dart2js were in focus. This yielded good results, such as a 17% reduction in minified output size and a 15% improvement in compilation time in one of the tested samples.
There are also some changes made outside the core Dart SDK. One is protocol buffers (protobuf) which are a platform-neutral mechanism for serializing structured data. Dart is now an officially protobuf supported language.
They have created a small sample for knative—a platform based on Kubernetes for building, deploying, and managing serverless workloads.
For more details, visit the Dart Blog post.
Google’s Dart hits version 2.0 with major changes for developers
C# 8.0 to have async streams, recursive patterns and more