
Dart 3 Updates
Use when writing switch statements, refactoring if-else chains, creating data classes...
Install
npx skills add evanca/flutter-ai-rules --skill dart-3-updates -g -a claude-code -y- Repository
- evanca/flutter-ai-rules668
- Category
- Writing
- Updated
- 5d ago
- License
- MIT
- Context cost
- Mediumabout 1,962 tokens
- Runs scripts
- No, instructions only
What it does
Use when writing switch statements, refactoring if-else chains, creating data classes, choosing records vs classes, destructuring values, or modernizing pre-Dart-3 code.
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
switchstatements orif-elsechains. - 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
// 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');
}
ifconditions must evaluate to abool.- In
if-case, variables declared in the pattern are scoped to the matching branch. - If the pattern does not match, control flows to the
elsebranch (if present).
switch statements
switch (command) {
case 'quit':
quit();
case 'start' || 'begin': // logical-or pattern
startGame();
default:
print('Unknown command');
}
- Each matched
casebody executes and jumps to the end,breakis not required. - Non-empty cases can end with
continue,throw, orreturn. - Use
defaultor_to handle unmatched values. - Empty cases fall through; use
breakto prevent fallthrough in an empty case. - Use
continuewith a label for non-sequential fallthrough. - Use logical-or patterns (
case a || b) to share a body between cases.
switch expressions
final color = switch (shape) {
Circle() => 'red',
Square() => 'blue',
_ => 'unknown',
};
- Omit
case; use=>for bodies; separate cases with commas. - Default must use
_(notdefault). - Produces a value.
