The Cascade Operator (..)
Chain calls on one object.
The Cascade Operator (..) is a free Dart Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Repetition Problem
When you set up one object, you often repeat its name on every line. Dart's cascade lets you skip that repetition and stay focused on the work.
Meet the Double Dot
The cascade operator is two dots, written as two periods. It runs a method or sets a field on an object without ending the chain.
var b = StringBuffer()
..write('Hi')
..write('!');It Returns the Object
Here is the magic: a cascade always returns the original object, not the method's result. So you can keep chaining as long as you like.
Setting Fields With Cascades
You can assign fields through a cascade too, not just call methods. Each line configures one more part of the same fresh object.
var p = Paint()
..color = blue
..width = 4;Before Cascades
Without cascades you assign the object to a variable, then mention that variable on every single line. It works, but it is noisy.
var b = StringBuffer();
b.write('a');
b.write('b');After Cascades
With cascades, the same setup becomes one tidy expression. The object is named once and every step hangs off it. ✨
var b = StringBuffer()
..write('a')
..write('b');Cascades Are an Expression
Because the whole chain is one expression, you can assign it straight to a variable. The configured object lands ready to use.
Mixing Calls and Assignments
You can freely mix method calls and field assignments in one cascade. Dart applies each line to the same object, top to bottom.
var list = []
..add(1)
..length;Watch the Semicolon
A cascade chain is still one statement, so the semicolon goes only at the very end. Putting one mid-chain breaks the chain in two.
Where Cascades Shine
Cascades are perfect for builders and config objects, like a StringBuffer or a Flutter widget that needs several quick tweaks.
Cascade vs Method Chain
A normal chain needs each method to return the right object. A cascade does not care what they return, since it always hands back the original.
Quick Check
What does a cascade operator return?
Recap
The cascade (..) configures one object across many lines, returns that object, and ends with a single semicolon. Cleaner setup, less repetition. 🎯
Frequently asked questions
Is the “The Cascade Operator (..)” lesson free?
Yes — the full text of “The Cascade Operator (..)” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “The Cascade Operator (..)”?
Chain calls on one object. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Cascade Operator (..)” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The Cascade Operator (..)
- Null-Shorting Cascades (?..)
- Spread and Null-Aware Spread
- Collection if and for