In this tutorial you will learn about the Dart Cascade notation (..) and its application with practical example.
Dart Cascade notation(..) Operator
Cascades (..) allow you to perform a sequence of operations on the same object. The Cascades notation(..) is similar to method chaining that saves you number of steps and need of temporary variable.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
class Demo { var a; var b; void setA(x) { this.a = x; } void setB(y) { this.b = y; } void showVal(){ print(this.a); print(this.b); } } void main() { Demo d1 = new Demo(); Demo d2 = new Demo(); print("W3Adda - Dart Cascade Notation"); // Without Cascade Notation d1.setA(20); d1.setB(25); d1.showVal(); // With Cascade Notation d2..setA(10) ..setB(15) ..showVal(); } |
Output:-