dart-use-primary-constructors
Installation
SKILL.md
Dart Primary Constructors & New Constructor Syntax Skill
Use this skill when helping users write, refactor, or debug code using Dart's Primary Constructors feature.
Dart Version Requirements
- Dart 3.13 and above: Primary constructors are enabled by default.
- Dart 3.12: The feature is available but experimental. Users must explicitly enable the experiment flag
primary-constructorsvia--enable-experiment=primary-constructorsor inanalysis_options.yaml:
analyzer:
enable-experiment:
- primary-constructors
- Dart 3.11 and earlier: Primary constructors are not supported.
1. Overview
Primary Constructors allow developers to declare a non-redirecting generative constructor as well as a set of instance variables directly in the class header. This significantly reduces boilerplate and improves code readability.