Null-Shorting Cascades (?..)
Cascade safely on nullable objects.
The Nullable Trap
A plain cascade on a value that might be null will crash. Calling a method on null throws an error before any line runs.
Meet Null-Shorting
Dart gives you a safe version: the null-shorting cascade, written as question mark then two dots. It only runs when the object is not null.
button?..text = 'Save'
..onTap = save;All lessons in this course
- The Cascade Operator (..)
- Null-Shorting Cascades (?..)
- Spread and Null-Aware Spread
- Collection if and for