dart3-idioms-and-coding-standards

Enforces Dart 3 declaration choices, exhaustive switches, immutability, and complexity limits.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/zakariaf/NearlyStop --skill dart3-idioms-and-coding-standards-zakariaf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dart3-idioms-and-coding-standards
Source: https://github.com/zakariaf/NearlyStop/tree/main/.claude/skills/dart3-idioms-and-coding-standards
Command: npx skills add https://github.com/zakariaf/NearlyStop --skill dart3-idioms-and-coding-standards-zakariaf

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Dart 3 offers many overlapping constructs (sealed classes, records, enums, class modifiers, codegen packages), and choosing the wrong one silently discards compile-time safety. This Skill gives a single verdict for every declaration so runtime failures become compile errors instead. ## Core Features & Use Cases - Construct verdicts: Rules for when to use sealed classes, enums, records, final/abstract interface class, and when to skip base, extension type, equatable, and fpdart/dartz. - Immutability and identity standards: Hand-rolled value types with copyWith and ==/hashCode, freezed for non-trivial types, and stable id-based identity. - Enforcement script: scripts/check-dart3-idioms.sh greps a codebase for hard bans (banned packages, experiment flags) and advisories (default:, late, Map<String, dynamic>, SCREAMING_CAPS). - Use Case: When adding a new variant to a sealed Payment type, the Skill ensures every switch is exhaustive with no default:, so the compiler flags every unhandled site. ## Quick Start Review my Dart file and tell me whether each declaration should be a sealed class, enum, record, or final class under these standards.

Frequently Asked Questions about dart3-idioms-and-coding-standards

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

FAQPage Schema
When should I use a sealed class vs an enum in Dart 3?

Start with an enum when the set is closed and every member is payload-free, since enums get compiler exhaustiveness in a switch. Convert to a sealed class with final class variants the moment any member needs a field, rather than adding nullable fields to the enum.

How do I make a Dart switch exhaustive without a default case?

Switch on a sealed type or enum and omit both default: and case _:. A missing branch then reports non_exhaustive_switch_statement from dart analyze and fails dart compile, so adding a variant becomes a compile error at every unhandled site.

Should I use freezed or equatable for Dart value types?

Hand-roll trivial immutables of one to three fields with @immutable, a const constructor, and final fields. Use freezed when copyWith, equality, and sealed-union boilerplate dominates; skip equatable since operator == plus Object.hash covers it in about five lines.

Why is using late or the bang operator discouraged in Dart?

late disables null-safety checking and throws LateInitializationError at runtime, while ! throws TypeError when wrong. Model genuinely absent values as nullable T? and handle them with ?., ??, or flow promotion instead.

What are the recommended Dart method and file length limits?

Methods cap at roughly 30 lines, build() at 80, files at 300, logic nesting at 3, and widget build nesting at 5. These are firm refactor prompts, and a cohesive overrun such as a single state machine can be justified in the PR.

When are records appropriate in Dart code?

Records suit ephemeral multi-value returns inside a single layer, like an (int row, int col) coordinate, with named fields once they survive a few lines. Never return a record from a repository, store it, or pass it across a widget constructor; use a named class instead.