dart-language-syntax
Installation
SKILL.md
Writing Idiomatic Dart
Contents
- Variables and State Management
- Functions and Closures
- Records and Pattern Matching
- Generics and Type Safety
- Workflow: Refactoring to Idiomatic Dart
- Examples
Variables and State Management
Manage state and variable declarations using strict mutability and type inference rules.
- Prefer
var: Usevarfor local variables when the assigned type is obvious (e.g.,var name = 'Bob';). Use explicit types when the type is not immediately clear from the initializer. - Enforce Immutability: Use
finalfor variables that should not be reassigned after initialization. Useconstfor compile-time constants and to create canonicalized, immutable object instances. - Leverage
late: Use thelatemodifier to defer initialization of non-nullable variables until their first use, especially for expensive computations or when initialization requires access tothis. - Implement Wildcards: Use the wildcard variable
_(requires Dart 3.7+) to discard unused values in local declarations, closures, or pattern matching without triggering unused variable warnings.
Functions and Closures
Structure functions for maximum composability and minimal boilerplate.