What's New in Dart 3.9: Faster Tools, Smarter Analysis, and AI Integration
Smarter Null-Safety Analysis
Dart 3.9 enhances type promotion, reachability, and definite assignment with deeper null-safety awareness. This results in more accurate warnings for dead code and redundant null checks. To enable these improvements, set your SDK constraint:
# pubspec.yaml
environment:
sdk: ^3.9.0Here’s a quick example where the analyzer now catches an unreachable branch:
int? n;
if (n == null) return;
// n is guaranteed to be non-null below, so the extra 'if' is highlighted:
if (n != null) print(n.isEven); // dead_code / redundant check
print(n.isEven);Faster Command-Line Interface (CLI)
Commands like dart analyze and dart fix now run from an AOT (Ahead-Of-Time) snapshot of the analysis server, eliminating JIT compilation for each call. On real-world packages, dart analyze is now up to 1.5x faster, with even more significant speed-ups for shorter commands.
Official MCP Server for AI Assistant Integration
The new Dart and Flutter MCP Server acts as a bridge between your project and compatible AI assistants like Gemini CLI, GitHub Copilot, and Cursor. It provides secure access to your project's context, enabling assistants to perform actions like fixing errors, managing dependencies, and running tests. This feature is experimental and requires Dart 3.9+.
To start the server for a compatible client, run:
# The MCP server command is 'dart mcp-server'
dart mcp-serverMore Precise Dependency Management with Pub
- Git Tag Resolution: You can now resolve Git dependencies using tags via
tag_pattern, which is perfect for versioned releases likevX.Y.Z. - Flutter Version Pinning: Pub now respects the upper bound for the
flutterSDK in your root package. This allows you to pin your project to a specific Flutter version, causingpub getto fail if the SDKs don't match.
# pubspec.yaml — example of git + tag_pattern and a strict Flutter pin
environment:
sdk: ^3.9.0
flutter: 3.35.0
dependencies:
my_dependency:
git:
url: https://github.com/example/my_dependency
tag_pattern: v{{version}}
version: ^2.0.1Compiler Updates: Cross-Compilation and Architectures
Dart now supports cross-compilation on Linux for ARM32 and RISC-V64 architectures, with improved documentation for dart compile. Concurrently, 32-bit x86 support is now deprecated, mainly affecting older emulators.
What This Means for Your Team
- Fewer Hidden Bugs: Enhanced null-safety analysis catches dead code and redundant checks during the
analyzestep, simplifying code reviews and reducing regressions. - Faster Development Cycles: The AOT snapshot for the analysis server reduces friction from frequent local checks (
analyze,fix), a noticeable improvement in monorepos and large Flutter projects. - More Predictable Dependencies: Using
tag_patternfor Git dependencies prevents accidental commits from being used, while pinning theflutterversion ensures the entire team works with the same SDK. - Seamless AI Tool Integration: The MCP server provides a standardized way for AI assistants to understand your project and perform tasks like fixing runtime errors or suggesting packages, saving valuable time.
- Expanded Platform Support: Cross-compilation for Linux ARM and RISC-V64 opens up possibilities for edge computing and embedded systems. Note that 32-bit x86 is being phased out, so plan to update any legacy emulators.
Your Action Plan: A Checklist
- Update SDK Constraints: In
pubspec.yaml, setsdk: ^3.9.0. Then rundart pub upgrade. - Enable New Lints: Add
switch_on_typeandunnecessary_unawaitedto youranalysis_options.yaml. Rundart analyzeanddart fix --apply. - Benefit from Faster Tooling: Start using the new CLI binaries. Measure the performance gain in your repository with
time dart analyze. - Organize Git Dependencies: If you use version tags for releases, add the
tag_patternto the relevant entries inpubspec.yaml. - Experiment with the MCP Server: If you use an AI assistant, configure it to launch
dart mcp-serverand test prompts like 'fix this layout error.'
Conclusion
Dart 3.9 is a practical update focused on saving you time and reducing noise in your codebase. With faster tooling, smarter null analysis, and more disciplined dependency management, it's a valuable upgrade. If you regularly use the Dart CLI, rely on Git dependencies, or are exploring ARM/RISC-V targets, updating now is highly recommended.