dart-use-primary-constructors

Refactor Dart 3.13+ class headers to primary constructor syntax.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/mordechai30/.agents --skill dart-use-primary-constructors
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dart-use-primary-constructors
Source: https://github.com/mordechai30/.agents/tree/main/skills/dart-use-primary-constructors
Command: npx skills add https://github.com/mordechai30/.agents --skill dart-use-primary-constructors

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the verbosity of traditional Dart constructor syntax by guiding developers through the implementation of primary constructors, which consolidate field declarations and initialization into the class header.

Core Features & Use Cases

  • Syntax Migration: Automatically refactors legacy generative constructors to the concise primary constructor format.
  • Scope Management: Provides guidance on utilizing the Primary Initializer Scope for non-late field initializers.
  • Use Case: Use this skill when upgrading a codebase to Dart 3.13+ to reduce boilerplate in data models and entity classes by moving field definitions directly into the class signature.

Quick Start

Use the dart-use-primary-constructors skill to refactor the User class in my current file to use the new primary constructor syntax.

Frequently Asked Questions about dart-use-primary-constructors

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a Dart class to use primary constructors?

To refactor a Dart class to use primary constructors, you move field declarations and initialization directly into the class header. This reduces boilerplate by applying concise syntax and managing initializer lists for Dart 3.13+ projects.

What are primary constructors in Dart and what problem do they solve?

Primary constructors in Dart consolidate field declarations and initialization into the class header. They solve the problem of verbose traditional constructor syntax, reducing boilerplate and improving code readability for data models.

Does primary constructor syntax work with older Dart projects or do I need Dart 3.13?

Primary constructor syntax requires Dart 3.13 or newer. You must upgrade your project environment to this version before refactoring legacy generative constructors into the concise primary constructor format.

How does the Primary Initializer Scope work for non-late field initializers in Dart?

The Primary Initializer Scope manages non-late field initializers within the class header. When using primary constructors, you must adhere to specific scoping rules to correctly differentiate between declaring and initializing parameters.

When should I not use primary constructors in Dart?

You should avoid primary constructors when working with Dart versions older than 3.13 or when your class requires complex initializer list logic that exceeds the abbreviated concise constructor syntax capabilities.

What is the best way to modernize Dart class constructors and reduce boilerplate?

The best way to modernize Dart class constructors is migrating to primary constructors. This moves field definitions into the class signature, consolidating declarations and reducing boilerplate compared to traditional generative constructors.