Google Dart 3.3 released, with new model for JavaScript interop to support Flutter WebAssembly

Google Dart 3.3 released, with new model for JavaScript interop to support Flutter WebAssembly

Google has released Dart 3.3, described as laying the groundwork for web applications compiled to WebAssembly, and including a new incompatible model for JavaScript interop as well as a feature called extension types.

The popularity of the Dart language is tied to that of Flutter, the cross-platform framework for mobile, web and desktop, which uses Dart, though it can also be used for general-purpose development. Dart compiles to native executables for Arm32, Arm64 or x86_64, or to JavaScript. 

The Flutter team is also interested in compiling to WebAssembly, for which Dart currently has experimental support. In March 2023 at the Wasm I/O event in Barcelona, Kevin Moore, Google Flutter and Dart product manager, said “we’re seeing 1.5 to, in some cases, 3 times” performance improvements versus compilation to JavaScript, based though on “very limited benchmarking.” Unlike Microsoft’s C#, Dart compiled to WebAssembly uses WasmGC, the new standard API for garbage-collected languages in Wasm, though currently this only works in Chromium-based browsers and Firefox, not in Safari.

Dart 3.3 includes an important step towards production use of Wasm support, with a new model for JavaScript interop. “Now Dart developers have access to a typed API for interacting with JavaScript,” explained Moore in a post published at the end of last week. The new model makes use of extension types, described as “a compile-time abstraction that ‘wraps’ an existing type with a different, static-only interface.” The advantage is that they can modify an existing type’s interface without any overhead, unlike wrapper classes which require additional runtime objects, making them ideal for efficient JavaScript interop.

Material Design samples in Flutter compiled to Wasm, running in Firefox

Using this new JavaScript model for interop is required for Wasm support, but requires migrating older code. The team said: “If you maintain a public Flutter package that uses dart:html or any of the other Dart SDK web libraries, you should migrate to package:web as soon as possible. package:web is replacing dart:html and other web libraries as Dart’s web interop solution long-term.” Developers can expect some friction while this is under way.

Wasm support is mainly for Flutter but not entirely. The team notes on Github: “Although Wasm was originally designed for running native code on the web, Wasm has since evolved into a general technology for running compiled code across multiple platforms.” Future use cases could include using Wasm-compiled Dart for server-side code.

Moore also noted in his post that Google has released an AI Dart SDK, which uses Google’s Gemini AI models via package:google_generative_ai. A separate post also from last week describes how the new package can be used for text summarization, chatbots, visual search, and interpreting charts and diagrams. Dart support will be added soon to Google’s AI Studio, said Flutter Global product manager Ander Dobo. The introduction of the AI Dart SDK shows how Google is using its support for the open-source Dart and Flutter projects to point developers towards its AI services.