Dart Records
Dart Records Overview
Records are a new primitive type in Dart 3 that enable lightweight data grouping without requiring class definitions. They provide an elegant syntax for bundling multiple values together, especially useful for returning multiple values from functions and working with pattern matching.
Key Features
1. Record Syntax
- Basic positional record creation
- Type annotations for records
- Immutable value semantics
2. Named Records
- Field labels in records
- Mixing positional and named fields
- Type system support
3. Record Decomposition
- Destructuring into variables
- Pattern matching in assignments
- Ignoring fields with
_
4. Pattern Matching with Records
- Switch expressions with records
- Record patterns in if-case
- Nested record matching
5. Advanced Record Usage
- JSON serialization
- Performance characteristics
- API design considerations