Mobile development

Stage 1 · Lesson 5 of 10

Sealed classes, records and patterns

Dart fundamentals

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

  • GuideFree
    Dart Language Tour

    Google · Beginner

    The official tour: read it in order and rerun every example in DartPad

Practise

  • Dart, TypeScript, Kotlin and Swift tracks with small exercises and free mentor feedback

Keep handy

  • Its Dart tutorial pages work as a quick lookup while you do the tour

Also worth your time

Mark this stage as not done?