dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use…
Applies Dart 3 pattern matching, switch expressions, and destructuring idiomatically to validate data schemas, handle algebraic data types, and decompose control flow. Use when refactoring complex if-else chains, parsing polymorphic JSON or API responses, destructuring Lists,
$ npx -y skills add dart-lang/skills --skill dart-use-pattern-matching --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/dart-use-pattern-matchingContext preview
The summary Claude sees to decide when to auto-load this skill.
Applies Dart 3 pattern matching, switch expressions, and destructuring idiomatically to validate data schemas, handle algebraic data types, and decompose control flow. Use when refactoring complex if-else chains, parsing polymorphic JSON or API responses, destructuring Lists,
name: dart-use-pattern-matching description: >- Applies Dart 3 pattern matching, switch expressions, and destructuring idiomatically to validate data schemas, handle algebraic data types, and decompose control flow. Use when refactoring complex if-else chains, parsing polymorphic JSON or API responses, destructuring Lists, URI/path segments, String.split() tokens, Records, or Maps, or enforcing exhaustiveness on sealed classes. Don't use for simple boolean conditions, single-variable type promotion (use `is`), or basic collection filtering. metadata: model: models/gemini-3.1-pro-preview last_modified: Wed, 23 Sep 2026 22:10:00 GMT
Apply specific pattern types based on the data structure and desired outcome. Follow these conditional guidelines:
Select the appropriate switch construct based on the execution context:
Implement patterns using the following syntax and rules:
Pattern matching and switch expressions should simplify code, not add syntactic overhead. Observe the following boundaries:
When checking or promoting a single variable, use standard `is` checks instead of `if-case` patterns that introduce shadow aliases.
// ✅ Promotes `key` directly in-place without extra variables
for (final MapEntry(:key, :value) in map.entries) {
if (key is String && value != null) {
process(key, value);
}
} // ❌ Anti-pattern: Introduces unnecessary alias variable `k`
for (final MapEntry(:key, :value) in map.entries) {
if (key case final String k when value != null) {
process(k, value);
}
}When mapping or returning values where both `null` and a type `T` are valid and handled identically, match the nullable type `T?` directly rather than creating redundant `null` arms.
// ✅ Clean nullable pattern match
switch (value) {
final String? s => s,
_ => throw FormatException('Invalid value: $value'),
} // ❌ Redundant separate null arm
switch (value) {
final String s => s,
null => null,
_ => throw FormatException('Invalid value: $value'),
}Do not use `if-case` in loops or
Agent skills for Dart, maintained by the Dart team. A collection of skills providing tailored instructions for common Dart development workflows.
Write and organize unit tests for functions, methods, and classes using `package:test`. Use…
Architectural patterns, entrypoint structure, exit codes, stream routing, and subprocess…
Collect coverage using the coverage packge and create an LCOV report
Uses get_runtime_errors and lsp to fetch an active stack trace, locate the failing line,…
Define and generate mock objects for external dependencies using `package:mockito` and…
Replace the usage of `expect` and similar functions from `package:matcher` to…