Stage 1 · Lesson 5 of 10
Sealed classes, records and patterns
3 added tools for a value that can take one of a few shapes. A has a fixed list of subclasses, such as Loading, Loaded and Failed. A switch over it must handle every one.
So if you add a new case, the compiler lists each place you need to update. Records group a few values without writing a class, as in (String, int) or (name: 'Ana', age: 30). They are handy for returning two things from one function. Pattern matching pulls values out of these shapes inside switch and if-case.
Common trapfalling back to a nullable data field plus a bool isLoading flag, which allows impossible states.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with
- GuideFreeDart Language Tour
Google · Beginner
The official tour: read it in order and rerun every example in DartPad