dart-sdk-changelog
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDart SDK Changelog & Version Feature Guide (Dart 1.x to Modern Dart 3.x)
Dart SDK 变更日志与版本特性指南(Dart 1.x 至现代 Dart 3.x)
This skill provides an authoritative, structured guide to Dart language features, core library APIs, tooling changes, version requirements, experimental feature flags (), static metaprogramming (Macros & Augmentations), and legacy modernization runbooks sourced directly from the official Dart SDK CHANGELOG.
--enable-experiment本技能提供一份权威、结构化的指南,涵盖Dart语言特性、核心库API、工具变更、版本要求、实验特性标志()、静态元编程(Macros & Augmentations)以及遗留代码现代化手册,所有内容均直接源自官方Dart SDK CHANGELOG。
--enable-experiment🎯 Parent Guide: How to Find the minSdk
for Any Dart Feature or API
minSdk🎯 核心指南:如何查找任意Dart特性或API的minSdk
minSdkWhen writing or reviewing Dart code, selecting the correct minimum SDK lower bound () in is essential to ensure syntax and core APIs compile across target environments.
minSdkpubspec.yaml在编写或审核Dart代码时,在中选择正确的最低SDK下限()至关重要,这能确保语法和核心API在目标环境中正常编译。
pubspec.yamlminSdk1. Language Version vs. SDK Version
1. 语言版本 vs. SDK版本
- Language Version (): In
major.minor, the lower bound ofpubspec.yaml(for exampleenvironment.sdkor^3.13.0) dictates which language grammar and compiler semantics are enabled.>=3.12.0 <4.0.0- Patch numbers (,
.1) do not affect language grammar..2 - Using a Dart 3.13 feature (like Primary Constructors) requires .
sdk: '^3.13.0'
- Patch numbers (
- Core Library APIs: Methods and classes (for example ,
Future.pause) are added in specific SDK versions.List.unmodifiableOf - Per-file override: A file can specify on line 1 to force an earlier language version.
// @dart = 3.12
- 语言版本():在
major.minor中,pubspec.yaml的下限(例如environment.sdk或^3.13.0)决定了启用的语言语法和编译器语义。>=3.12.0 <4.0.0- 补丁版本(、
.1)不会影响语言语法。.2 - 使用Dart 3.13的特性(如主构造函数)需要设置。
sdk: '^3.13.0'
- 补丁版本(
- 核心库API:方法和类(例如、
Future.pause)是在特定SDK版本中新增的。List.unmodifiableOf - 单文件覆盖:文件的第1行可以指定,强制使用更早的语言版本。
// @dart = 3.12
2. Fast minSdk
Language Feature Matrix
minSdk2. 快速查询minSdk
的语言特性矩阵
minSdk| Feature / Syntax | Minimum SDK | Example Syntax | Reference |
|---|---|---|---|
| Primary Constructors | | | 3.13 Guide |
| Constructor Keyword Shorthands | | | 3.13 Guide |
| Private Named Parameters | | | 3.12 Guide |
Wildcard Variables ( | | | 3.7 Guide |
| Type Inference Using Bounds | | Inferred types respect type parameter bounds | 3.7 Guide |
| Digit Separators | | | 3.6 Guide |
| Extension Types | | | 3.0-3.5 Guide |
| Private Field Promotion | | | 3.0-3.5 Guide |
| Records (Tuples) | | | 3.0-3.5 Guide |
| Pattern Matching & Destructuring | | | 3.0-3.5 Guide |
| Switch Expressions | | | 3.0-3.5 Guide |
| If-Case Statements & Elements | | | 3.0-3.5 Guide |
| Sealed Classes & Exhaustiveness | | | 3.0-3.5 Guide |
Class Modifiers ( | | | 3.0-3.5 Guide |
| 100% Sound Null Safety Enforced | | Non-null-safe mode disallowed | 3.0-3.5 Guide |
| Super-Initializer Parameters | | | Dart 2 Milestones |
| Enhanced Enums | | | Dart 2 Milestones |
| Named Arguments Anywhere | | | Dart 2 Milestones |
| Constructor Tear-Offs | | | Dart 2 Milestones |
Triple-Shift Operator ( | | | Dart 2 Milestones |
Generic Type Aliases ( | | | Dart 2 Milestones |
Sound Null Safety ( | | Sound static non-nullable types | Dart 2 Milestones |
| Extension Methods | | | Dart 2 Milestones |
Spread Operators ( | | | Dart 2 Milestones |
Collection | | | Dart 2 Milestones |
Sound Type System & Optional | | Static sound types replace dynamic checks | Dart 2 Milestones |
👉 For deep-dive and verification procedures, see How to Find minSdk and the Full Version Matrix.
| 特性/语法 | 最低SDK版本 | 示例语法 | 参考文档 |
|---|---|---|---|
| 主构造函数(Primary Constructors) | | | 3.13指南 |
| 构造函数关键字简写(Constructor Keyword Shorthands) | | | 3.13指南 |
| 私有命名参数(Private Named Parameters) | | | 3.12指南 |
通配符变量( | | | 3.7指南 |
| 使用边界进行类型推断(Type Inference Using Bounds) | | 推断类型遵循类型参数边界 | 3.7指南 |
| 数字分隔符(Digit Separators) | | | 3.6指南 |
| 扩展类型(Extension Types) | | | 3.0-3.5指南 |
| 私有字段提升(Private Field Promotion) | | | 3.0-3.5指南 |
| 记录(Records,即元组) | | | 3.0-3.5指南 |
| 模式匹配与解构(Pattern Matching & Destructuring) | | | 3.0-3.5指南 |
| Switch表达式(Switch Expressions) | | | 3.0-3.5指南 |
| If-Case语句与元素(If-Case Statements & Elements) | | | 3.0-3.5指南 |
| 密封类与穷尽性检查(Sealed Classes & Exhaustiveness) | | | 3.0-3.5指南 |
类修饰符( | | | 3.0-3.5指南 |
| 强制100%可靠空安全 | | 不允许非空安全模式 | 3.0-3.5指南 |
| 超初始化参数(Super-Initializer Parameters) | | | Dart 2里程碑 |
| 增强枚举(Enhanced Enums) | | | Dart 2里程碑 |
| 任意位置的命名参数(Named Arguments Anywhere) | | | Dart 2里程碑 |
| 构造函数剥离(Constructor Tear-Offs) | | | Dart 2里程碑 |
三位移位运算符( | | | Dart 2里程碑 |
泛型类型别名( | | | Dart 2里程碑 |
可靠空安全( | | 可靠的静态非空类型 | Dart 2里程碑 |
| 扩展方法(Extension Methods) | | | Dart 2里程碑 |
展开运算符( | | | Dart 2里程碑 |
集合 | | | Dart 2里程碑 |
可靠类型系统与可选 | | 静态可靠类型替代动态检查 | Dart 2里程碑 |
👉 如需深入了解和验证步骤,请查看如何查找minSdk和完整版本矩阵。
⚡ Subskill Spotlights
⚡ 子技能亮点
Subskill: Augmentations & Static Metaprogramming (Macros)
子技能:增强功能(Augmentations)与静态元编程(Macros)
- Augmentation Syntax: Declare ,
augment class, and wrap methods usingimport augment.augmented() - Macro Phases: Understand Type, Declaration, and Definition macro execution in the analysis server.
- In-Memory Code Gen: Eliminate with zero-disk
build_runnerpollution. 👉 Read the full Macros & Augmentations Guide..g.dart
- 增强语法:声明、
augment class,并使用import augment包裹方法。augmented() - 宏阶段:了解分析服务器中Type、Declaration和Definition宏的执行流程。
- 内存代码生成:无需,避免磁盘上生成
build_runner文件造成污染。 👉 阅读完整的Macros与增强功能指南。.g.dart
Subskill: Experimental Features & Compiler Flags (--enable-experiment
)
--enable-experiment子技能:实验特性与编译器标志(--enable-experiment
)
--enable-experiment- Enabling Experiments: Configure (
analysis_options.yaml), CLI flags (analyzer.enable-experiment), and VS Code settings.dart --enable-experiment=... - Release Pipeline: Understand the graduation path across Beta preview, Stable-gated, and Stable-ungated tiers. 👉 Read the full Experimental Features Guide.
- 启用实验特性:配置(
analysis_options.yaml)、CLI标志(analyzer.enable-experiment)和VS Code设置。dart --enable-experiment=... - 发布流程:了解实验特性从Beta预览版、稳定版 gated 到稳定版 ungated 的升级路径。 👉 阅读完整的实验特性指南。
Subskill: Rescuing Legacy Codebases (Dart 1.x & Pre-2.12 to Modern Dart)
子技能:修复遗留代码库(从Dart 1.x & 2.12之前版本升级到现代Dart)
- Sound Null Safety Migration: Transform annotations, uninitialized nullable fields, and defensive runtime assertions.
@required - Dependency Upgrades: Modernize environment bounds and replace deprecated legacy packages (
pubspec.yaml,pedantic, etc.). 👉 Read the full Legacy Codebase Rescue Guide.tuple
- 可靠空安全迁移:转换注解、未初始化的可空字段和防御性运行时断言。
@required - 依赖升级:更新的环境约束,替换已废弃的遗留包(如
pubspec.yaml、pedantic等)。 👉 阅读完整的遗留代码库修复指南。tuple
📚 Table of Contents (TOC) & Version Archive
📚 目录(TOC)与版本档案
| Release / Guide | Focus Area | Key Additions | Reference Document |
|---|---|---|---|
| Macros & Augmentations | Metaprogramming | | Macros & Augmentations Guide |
| Experimental Features | Compiler Flags | | Experiments Guide |
| Legacy Rescue | Migration Runbook | Dart 1.x/2.x to Modern 3.x modernization pipeline, null-safety bridge, package replacements | Rescue Guide |
| Dart 3.14 | FFI & JS Interop | | 3.14 Reference |
| Dart 3.13 | Language & Runtime | Primary constructors, | 3.13 Reference |
| Dart 3.12 | Language & Tooling | Private named parameters ( | 3.12 Reference |
| Dart 3.11 | Platform & Pub | Windows Unix domain sockets, Workspace globs ( | 3.11 Reference |
| Dart 3.10 | Extensibility & CLI | Analyzer plugins stable, Hooks (native assets) stable, | 3.10 Reference |
| Dart 3.9 | Analysis & Pub | AOT analysis server, git tag version solving, null-safety assumptions in flow analysis | 3.9 Reference |
| Dart 3.8 | Formatter & Docs | Doc imports ( | 3.8 Reference |
| Dart 3.7 | Language & Formatter | Wildcard variables ( | 3.7 Reference |
| Dart 3.6 | Language & Pub | Digit separators ( | 3.6 Reference |
| Dart 3.0 – 3.5 | Foundation & Major Features | Records, Patterns, Switch Expressions, Sealed Classes, Class Modifiers, Extension Types, Field Promotion, Wasm | 3.0–3.5 Reference |
| Dart 2.0 – 2.19 | Historical Milestones | Sound Null Safety (2.12), Enhanced Enums & Super-Params (2.17), Extension Methods (2.7), Spreads (2.3), Sound Type System (2.0) | Dart 2 Milestones |
| 版本/指南 | 重点领域 | 主要新增内容 | 参考文档 |
|---|---|---|---|
| Macros与增强功能 | 元编程 | | Macros与增强功能指南 |
| 实验特性 | 编译器标志 | | 实验特性指南 |
| 遗留代码修复 | 迁移手册 | Dart 1.x/2.x到现代3.x的现代化流程、空安全过渡、包替换 | 修复指南 |
| Dart 3.14 | FFI与JS互操作 | | 3.14参考文档 |
| Dart 3.13 | 语言与运行时 | 主构造函数、 | 3.13参考文档 |
| Dart 3.12 | 语言与工具 | 私有命名参数( | 3.12参考文档 |
| Dart 3.11 | 平台与Pub | Windows Unix域套接字、工作区通配符( | 3.11参考文档 |
| Dart 3.10 | 扩展性与CLI | 分析器插件稳定、Hooks(原生资产)稳定、 | 3.10参考文档 |
| Dart 3.9 | 分析与Pub | AOT分析服务器、Git标签版本解析、流分析中的空安全假设 | 3.9参考文档 |
| Dart 3.8 | 格式化工具与文档 | 文档导入( | 3.8参考文档 |
| Dart 3.7 | 语言与格式化工具 | 通配符变量( | 3.7参考文档 |
| Dart 3.6 | 语言与Pub | 数字分隔符( | 3.6参考文档 |
| Dart 3.0 – 3.5 | 基础与主要特性 | 记录、模式、Switch表达式、密封类、类修饰符、扩展类型、字段提升、Wasm | 3.0–3.5参考文档 |
| Dart 2.0 – 2.19 | 历史里程碑 | 可靠空安全(2.12)、增强枚举与超参数(2.17)、扩展方法(2.7)、展开运算符(2.3)、可靠类型系统(2.0) | Dart 2里程碑 |
🛠️ Recommended Runbooks
🛠️ 推荐操作手册
1. Working with Augmentations & Macros
1. 使用增强功能与Macros
- Review Macros & Augmentations Guide.
- Wire original files with and augmentation files with
import augment 'foo.g.dart';.augment library 'foo.dart'; - Use ,
augment class, and callaugment void method()to wrap original logic.augmented()
- 查看Macros与增强功能指南。
- 在原始文件中添加,在增强文件中添加
import augment 'foo.g.dart';。augment library 'foo.dart'; - 使用、
augment class,并调用augment void method()包裹原有逻辑。augmented()
2. Working with Experimental Feature Flags
2. 使用实验特性标志
- Check if the feature has already graduated to stable in the active SDK before adding a flag.
- If experimental, configure under
analysis_options.yaml.analyzer.enable-experiment: [name] - Pass to
--enable-experiment=name,dart run,dart test, andflutter run.flutter test - Ensure experimental code is isolated so production packages remain publishable on pub.dev.
- 在添加标志前,检查该特性在当前SDK中是否已升级到稳定版。
- 如果是实验特性,在的
analysis_options.yaml下进行配置。analyzer.enable-experiment: [name] - 在、
dart run、dart test和flutter run中传递flutter test参数。--enable-experiment=name - 确保实验代码被隔离,以便生产包可以在pub.dev上发布。
3. Modernizing / Rescuing a Legacy Codebase
3. 现代化/修复遗留代码库
- Check current language version from environment block.
pubspec.yaml - If pre-2.12, read the Legacy Rescue Guide.
- Execute the 4-stage pipeline: syntax cleanup → sound null safety → dependency bump (or
sdk: ^3.5.0) → Dart 3 modernization.^3.13.0
- 从的环境块中查看当前语言版本。
pubspec.yaml - 如果是2.12之前的版本,请阅读遗留代码修复指南。
- 执行四阶段流程:语法清理 → 可靠空安全迁移 → 依赖升级(或
sdk: ^3.5.0)→ Dart 3现代化。^3.13.0
4. Answering "What's New in Dart X.Y"
4. 回答“Dart X.Y版本有什么新特性”
- Identify the requested version.
- Read the corresponding reference document under .
references/ - Provide:
- Language syntax changes with before/after code snippets.
- Core library additions (,
dart:core,dart:async,dart:io,dart:js_interop,dart:isolate).dart:ffi - Tooling and CLI features (,
dart analyze,dart format,dart pub).dart build - Breaking changes and migration instructions.
- 确定用户请求的版本。
- 阅读下对应的参考文档。
references/ - 提供:
- 语言语法变更,包含变更前后的代码片段。
- 核心库新增内容(、
dart:core、dart:async、dart:io、dart:js_interop、dart:isolate)。dart:ffi - 工具与CLI特性(、
dart analyze、dart format、dart pub)。dart build - 破坏性变更与迁移说明。
5. Answering "How to find minSdk for X"
5. 回答“如何查找X的minSdk”
- Check the Language Feature Matrix and How to Find minSdk Guide.
- Specify the exact lower bound SDK constraint for (for example
pubspec.yaml).sdk: '^3.13.0' - Explain if the feature is a language grammar feature (requiring language version update) or a core library API.
- Show how to verify using .
dart analyze
- 查看语言特性矩阵和如何查找minSdk指南。
- 指定中确切的SDK下限约束(例如
pubspec.yaml)。sdk: '^3.13.0' - 说明该特性是语言语法特性(需要更新语言版本)还是核心库API。
- 展示如何使用进行验证。
dart analyze