Mobile development

Stage 1 · Lesson 2 of 10

Sound null safety

Dart fundamentals

In 3 a String can never be null; only a String? can. This is : the compiler makes you deal with the missing case before you use the value. Learn the tools in order of safety.

First, an if (name != null) check, after which Dart promotes the type to a plain String. Then ?. for safe access and ?? for a default, as in user.nickname ?? 'Guest'. Use required for that must be passed.

Use late for a non-null field you promise to set before its first use. Note that promotion works on local variables, not on public fields of a class.

Common trap! and late used to make errors go away: both move the failure to runtime.

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?