PlugWiki

dart-use-pattern-matching: a Dart team skill for switch expressions and patterns

A Dart team skill that makes Claude refactor with Dart 3 patterns, switch expressions and destructuring where they help.

Installs
19.3K
on skills.sh
Stars
537
on GitHub
Files
1
besides SKILL.md
Updated
Oct 2026
last repo commit

This skill tells Claude which Dart pattern to use for each job: map and list patterns for JSON, list patterns with rest elements for path segments, record patterns for multiple return values, and object patterns with sealed classes for exhaustiveness. It also says when not to use patterns, such as simple booleans, single-variable type promotion with is, or basic filtering.

It asks Claude to run dart analyze to check exhaustiveness and to test how map patterns treat omitted keys against explicit nulls. The folder holds SKILL.md and one example file, examples/json_patterns.dart. It edits your Dart code.

Good for

  • Dart developers parsing polymorphic JSON or API responses
  • Teams using sealed classes who want exhaustive switches
  • Anyone with long if-else chains to simplify

Install dart-use-pattern-matching

Claude Code

  1. 1

    Copy this prompt.

    Install the dart-use-pattern-matching skill in Claude Code. Run this command:
    
    npx skills add https://github.com/dart-lang/skills --skill dart-use-pattern-matching
    
    Then check that it loaded and tell me how to use it.
  2. 2

    Paste it into Claude Code. It shows the change and asks before running it.

Requires Node.js.

From its listing on skills.sh. Source.

What's in the skill

When it loads

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.

Sections in SKILL.md

  1. Contents
  2. Pattern Selection Strategy
  3. Switch Statements vs. Expressions
  4. Core Pattern Implementations
  5. Pragmatic Balance & Anti-Patterns
  6. 1. Prefer is Type Promotion over if-case for Single Promotable Variables
  7. 2. Consolidate Nullable Types in Switch Arms
  8. 3. Preserve Fast-Fail Validation (Do Not Silently Drop Data)
  9. 4. Avoid Single-Case or Boolean Switches
  10. 5. Use Object Destructuring for Multi-Field Unpacking, Not Single Properties or Passthroughs
  11. 6. Avoid if-case for Standalone Scalar Comparisons
  12. Workflows
  13. Task Progress: Implementing Pattern Matching
  14. Feedback Loop 1: Exhaustiveness Checking (Static Verification)
  15. Feedback Loop 2: Runtime Map & JSON Pattern Verification
  16. Examples

Key facts

Installs on skills.sh
19,292 as of 2026-11-02
Last repo commit
2026-10-16

What it includes

  • Which pattern fits JSON, paths, records, ADTs, ranges

    Conditional rules that map each data shape to map, list, record, object, relational, logical-or or wildcard patterns.

    Try: “Use switch expressions and patterns to parse this API response into sealed classes.”

    Read · Pattern selection strategy

  • Expression for values, statement for side effects

    Expressions must be exhaustive and have one expression per case. Statements fall through only on empty cases.

    Read · Switch statements versus expressions

  • Syntax and rules for 12 pattern kinds

    Logical-or, logical-and, relational, cast, null-check, null-assert, variable, wildcard, list, map, record and object patterns.

    Read · Core pattern implementations

  • Six cases where patterns add noise

    Prefer is promotion for one variable, consolidate nullable arms, keep fast-fail validation, avoid single-case switches and passthrough destructuring.

    Read · Pragmatic balance and anti-patterns

  • Run dart analyze, then check map pattern runtime behavior

    Checks exhaustiveness with dart analyze and verifies that omitted keys fail a map pattern while explicit nulls match.

    Runs code · Workflow and feedback loops

  • Runnable example of tagged JSON parsing

    Shows ApiResponse parsing into SuccessResponse and ErrorResponse, and processUserPayload.

    Read · examples/json_patterns.dart

From the official docs

Questions

What does dart-use-pattern-matching do?

It teaches Claude to apply Dart 3 pattern matching and switch expressions for JSON validation, list and path destructuring, records and sealed class hierarchies, and to avoid patterns where they add noise.

How do I install it?

Use the install box at the top of this page. The dart-lang/skills README also gives one command that installs every skill in the repo into the standard .agents/skills folder, if you want the whole set.

Does it run any code?

The workflow asks Claude to run dart analyze for exhaustiveness and dead-code warnings. The folder also has one example file, examples/json_patterns.dart. The skill itself bundles no other scripts.

When does it say not to use patterns?

The description says not to use it for simple boolean conditions, single-variable type promotion (use is), or basic collection filtering.

Is it safe to use?

It rewrites your Dart code to use patterns, so work in a git repository and review the diff. Run your tests, because the skill warns that a map pattern fails to match when an optional key is omitted from a JSON payload.

Information

updated Nov 2, 2026

Folder
skills/dart-use-pattern-matching

dart-lang/skillsskills.sh

Sources

Docs, issue trackers and discussions this page is built from.

Show all 2
  1. SKILL.md · github.com
  2. json_patterns.dart · github.com

Updated Nov 2, 2026.