Flutter ● ● ○ Dart 3.10

Kodebits Day 4: Cascade Notation

Apr 12 2026
Cascades (..) allow you to make a sequence of operations on the same object.

What does this code output?

class P {
  int x = 0;
  void add(int n) { x += n; }
}
void main() {
  var p = P()
    ..x = 2
    ..add(3)
    ..add(4);
  print(p.x);
}


Try it in the online Dart Playground →

[spoiler title="Solution"]

Answer:

9

Explanation:

.. is a cascade operator, which mutates the same instance, so here x goes 2 -> 5 -> 9.

[/spoiler]


Further Reading