Dart Macros — Compile-time Code Generation Without Build Runner
Dart 3.4 (Flutter 3.22) introduced Dart Macros as an experimental feature: compile-time code generation that works without build_runner . A single annotation can auto-generate fromJson / toJson , copyWith , or Equatable -style equality — all processed directly by the compiler.
What Are Dart Macros? Key Differences from build_runner
Traditional build_runner -based code generation has two pain points:
Slow build steps : You must manually run dart run build_runner build , which can take seconds to minutes on large projects
Generated file clutter : The .g.dart files need to be committed (or .gitignore d), causing team disagreements
Dart Macros are processed by the compiler itself, eliminating the separate build step.…