Cascade notation

on Saturday, 18th of July, 2020

Cascade notation is syntactic sugar in Dart that allows you to make a sequence of operations on the same object. You can use the "double dot" to call functions on objects and access properties. This "operator" is simply used to make your code cleaner and concise. It often saves you from having to create temporary variables.

example use from the Dart documentation:

// with cascade notation:
querySelector('#confirm') // Get an object.
  ..text = 'Confirm' // Use its members.
  ..onClick.listen((e) => window.alert('Confirmed!'))

// without cascade notation
var button = querySelector('#confirm');
button.text = 'Confirm';
button.onClick.listen((e) => window.alert('Confirmed!'));

Join thousands of Flutter developers.

Sign up for infrequent updates about Flutter and Dart.

You can get all this content and more in one place. Check out my new book Flutter in Action