by Manfred Steyer (SOFTWAREarchitekt.at)
dart2native
With Dart 2.6 onwards, the new dart2native
compiler is available in the Dart SDK.
Programmers can use the command to compile a Dart program ahead-of-time to native x64 machine code. The result is a self-contained executable compiled from the Dart file or an ahead-of-time snapshot that does not include the Dart runtime.
Read more about the compiler and how to create a standalone executable and/or AOT snapshot in the documentation. The feature derives from this issue on GitHub requesting the feature for desktop devices.
According to the release blog, “the executables start running in just a few milliseconds”. The provided sample starts, prints to stdout, and exists in 49 milliseconds.
A few caveats remain. Currently, there is no cross-compilation support for different operating systems. Nor is there signaling support for the executables, or support for dart:mirrors
and dart:developer
. However, these limitations may all be resolved in a future update, based upon developer need.
Code editor demo
The dart_console package comes bundled with a demo for kilo, a small code editor written in roughly 500 lines of code.
It clocks in at only 7MB. With it, you can create console apps.
SEE ALSO: How to supercharge innovation with a Dev Day
Check out the source code on GitHub.
Feature preview: Extension methods
Test out extension methods as the feature continues active development. Extension methods will call static functions and be able to define extension members for instance, methods, operators, setters, and getters.
Read about the design plans and considerations.
C# and Kotlin already use static extension methods. If timing goes well, extension methods will be included in the next SDK version.
Feature preview graduates to beta: dart:ffi
The new version of Foreign Function Interface in 2.6 introduces a number of breaking API changes. It makes APIs easier to use and provides easier access to memory.
SEE ALSO: Flutter developers survey: Documentation is key to Flutter’s success
From the changelog, here are the breaking changes this introduces:
- Breaking change: The API now makes use of static extension members. Static extension members enable the
dart:ffi
API to be more precise with types, and provide convenient access to memory through extension getters and setters. The extension members on Pointer
provide .value
and .value =
for accessing the value in native memory and []
and []=
for indexed access. The method asExternalTypedData
has been replaced with asTypedList
extension methods. And finally, Structs
do no longer have a type argument and are accessed using the extension member .ref
on Pointer
. These changes makes the code using dart:ffi
much more concise.
- Breaking change: The memory management has been removed (
Pointer.allocate
and Pointer.free
). Instead, memory management is available in package:ffi.
- Breaking change:
Pointer.offsetBy
was removed, use cast
and elementAt
instead.
- Faster memory load and stores.
- The dartanalyzer (commandline and IDEs) now reports
dart:ffi
static errors.
- Callbacks are now supported in AOT (ahead-of-time) compiled code.
Other changes
Miscellaneous changes include:
- Linter updated to 0.1.101
- Removed
Pointer.offsetBy
- dart:io library: Added
IOOverrides.serverSocketBind