dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains…
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 Records
$ npx -y skills add flutter/agent-plugins --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 Records
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 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: Sun, 06 Sep 2026 06:43: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 deserialization to filter elements if malformed data should trigger an error or diagnostic warning.
// ✅ Fast-fail with explicit diagnostic error
for (final raw in rawTasks) {
if (raw is! Map<String, dynamic>) {
throw FormatException('Expected Map item, got ${raw.runtimeType}: $raw');
}
_applyTask(raw);Agent plugins for Flutter, maintained by the Flutter team. A collection of plugins designed to extend AI agent capabilities for Flutter development.
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains…
Architectural patterns, entrypoint structure, exit codes, stream routing, and subprocess spawning for Dart command-line interface (CLI) applications. Use when…
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, apply a fix, and verify resolution via hot_reload.
Define and generate mock objects for external dependencies using `package:mockito` and `build_runner`. Use when unit testing classes that depend on complex…
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.