Dart Chapter 8 of 15
Records and Patterns
The Dart 3 features that changed everyday code: records, destructuring, pattern matching, switch expressions and sealed classes.
Dart 3 added a group of features that work together. Records bundle values, patterns take them apart, switch expressions choose between them, and sealed classes let the compiler check that you covered every case.
Lessons in this chapter
- Records in Dart: Return Multiple Values Without a ClassLearn Dart records: positional and named fields, record types, returning multiple values from a function, equality and destructuring.
- Patterns and Destructuring in DartLearn pattern matching in Dart 3: destructure lists, maps, records and objects, and use patterns in variables, if-case, for loops and switch.
- Switch Expressions in Dart 3Learn switch expressions in Dart: return a value from switch, match patterns and records, use guards, and get exhaustiveness checking.
- Sealed Classes in Dart: Exhaustive Type HierarchiesLearn sealed classes in Dart 3: model a fixed set of subtypes, get exhaustive switch checking, and represent state and results safely.