# Dart 3 Updates

Use when writing switch statements, refactoring if-else chains, creating data classes...

- Repository: https://github.com/evanca/flutter-ai-rules (668 stars)
- Category: Writing
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add evanca/flutter-ai-rules --skill dart-3-updates -g -a claude-code -y`
Codex: `npx skills add evanca/flutter-ai-rules --skill dart-3-updates -g -a codex -y`
Cursor: `npx skills add evanca/flutter-ai-rules --skill dart-3-updates -g -a cursor -y`
Gemini CLI: `npx skills add evanca/flutter-ai-rules --skill dart-3-updates -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add evanca/flutter-ai-rules`

## Description

Use when writing switch statements, refactoring if-else chains, creating data classes, choosing records vs classes, destructuring values, or modernizing pre-Dart-3 code.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Dart 3 Updates Skill

Apply Dart 3 language features, branches, patterns, pattern types, and records, correctly and idiomatically.

## When to Use

Use this skill when:

* Writing or refactoring `switch` statements or `if-else` chains.
* Creating new data-holding classes and deciding between sealed classes, records, or plain classes.
* Destructuring values from maps, lists, records, or objects.
* Modernizing pre-Dart-3 code to use patterns, exhaustiveness checks, or switch expressions.

---

## 1. Branches

### if / if-case

```dart
// Standard if
if (score >= 90) {
  grade = 'A';
} else if (score >= 80) {
  grade = 'B';
} else {
  grade = 'C';
}

// if-case: match and destructure against a single pattern
if (pair case [int x, int y]) {
  print('$x, $y');
}
```

- `if` conditions must evaluate to a `bool`.
- In `if-case`, variables declared in the pattern are scoped to the matching branch.
- If the pattern does not match, control flows to the `else` branch (if present).

### switch statements

```dart
switch (command) {
  case 'quit':
    quit();
  case 'start' || 'begin': // logical-or pattern
    startGame();
  default:
    print('Unknown command');
}
```

- Each matched `case` body executes and jumps to the end, `break` is **not required**.
- Non-empty cases can end with `continue`, `throw`, or `return`.
- Use `default` or `_` to handle unmatched values.
- Empty cases fall through; use `break` to prevent fallthrough in an empty case.
- Use `continue` with a label for non-sequential fallthrough.
- Use logical-or patterns (`case a || b`) to share a body between cases.

### switch expressions

```dart
final color = switch (shape) {
  Circle() => 'red',
  Square() => 'blue',
  _ => 'unknown',
};
```

- Omit `case`; use `=>` for bodies; separate cases with commas.
- Default must use `_` (not `default`).
- Produces a value.

### Exhaustiveness

The rest: https://github.com/evanca/flutter-ai-rules/blob/HEAD/skills/dart-3-updates/SKILL.md
