dart-use-primary-constructors

Refactor legacy Dart class constructors into modern primary constructor syntax.

2.8k|166|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/flutter/agent-plugins --skill dart-use-primary-constructors-flutter
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dart-use-primary-constructors
Source: https://github.com/flutter/agent-plugins/tree/main/skills/dart-use-primary-constructors
Command: npx skills add https://github.com/flutter/agent-plugins --skill dart-use-primary-constructors-flutter

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the verbosity and boilerplate associated with traditional Dart class constructors by guiding users through the adoption of primary constructors and modern syntax.

Core Features & Use Cases

  • Boilerplate Reduction: Automatically migrates standard class constructors to the concise primary constructor syntax.
  • Syntax Modernization: Assists in implementing empty-body semicolon shorthand and abbreviated concise constructor syntax.
  • Use Case: Use this skill when refactoring a large codebase to Dart 3.13+ standards to improve readability and maintainability by consolidating field declarations and constructor parameters.

Quick Start

Use the dart-use-primary-constructors skill to refactor the User class in the current file to use the 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 Dart class constructors to use primary constructor syntax?

To refactor Dart class constructors to primary constructor syntax, this skill migrates legacy generative constructors and field initializers into concise parameter declarations, reducing boilerplate and improving code clarity.

What are primary constructors in Dart and when should I migrate to them?

Primary constructors in Dart are a modern syntax feature that consolidates class field declarations and constructor parameters. You should migrate to them when updating a codebase to Dart 3.13+ standards to improve readability and reduce boilerplate.

Does primary constructor migration work with Dart 3.13 and later environments?

Yes, primary constructor migration specifically targets Dart 3.13+ development environments. The refactoring process ensures syntactically correct declaring parameters, initializer list scoping, and abbreviated constructor patterns for modern Dart compatibility.

What is the best way to reduce boilerplate in legacy Dart class definitions?

The best way to reduce boilerplate in legacy Dart class definitions is adopting primary constructor syntax. This modernization process consolidates field declarations and parameters, applying empty-body semicolon shorthand and abbreviated concise constructor patterns.

Can I use this refactoring for initializer list scoping in Dart?

Yes, this refactoring handles initializer list scoping during the migration to primary constructor syntax. It ensures that declaring parameters and field initializers are correctly scoped and syntactically valid in the updated Dart class structure.

Why does migrating to Dart primary constructors improve code maintainability?

Migrating to Dart primary constructors improves code maintainability by consolidating field declarations and constructor parameters into a concise syntax. This reduces verbosity and boilerplate, making large codebases easier to read and update.