0PricingLogin
Dart Academy · Lesson

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

  1. The Cascade Operator (..)
  2. Null-Shorting Cascades (?..)
  3. Spread and Null-Aware Spread
  4. Collection if and for
← Back to Dart Academy