Cascade Operator In Dart

Cascade Operator In Dart :

Cascade Operator In Dart
  • Cascade (..) is used to sequence of operations on the same object.
  • Cascade notation (..) is similar to method chaining that saves your number of steps and need of temporary variable.
class CasecadeOperator {
vara;
varb;

void setA(x) {
this.a= x;
  }

void setB(y) {
this.b= y;
  }

void showVal() {
    print(this.a);
    print(this.b);
  }
}

void main() {
CasecadeOperator obj1 = new CasecadeOperator();
CasecadeOperator obj2 = new CasecadeOperator();

//Without Cascade Notation
obj1.setA(20);
  obj1.setB(25);
  obj1.showVal();

//Casecade Notation
obj2
    ..setA(10)
    ..setB(15)
    ..showVal();
}

output
20
25
10
15