Stage 1 · Lesson 2 of 10
Sound null safety
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
- GuideFreeDart Language Tour
Google · Beginner
The official tour: read it in order and rerun every example in DartPad