Double And Triple Dots
Double dots(..) i.e cascade operator
Double dots(..) is known as cascade notation (allow you to make a sequence of operations on the same object). It allows you to not repeat the same target if you want to call several methods on the same object.This often saves you the step of creating a temporary variable and allows you to write more fluid code. Normally, we use the below way to define several methods on the same object.
//before var paint = Paint(); paint.color = Colors.black; paint.strokeCap = StrokeCap.round; paint.strokeWidth = 5.0; //after var paint = Paint() ..color = Colors.black ..strokeCap = StrokeCap.round ..strokeWidth = 5.0;
Triple dots(…) i.e. Spread Operator
Triple dots(…) also known as spread operator which provide a concise way to insert multiple values into a collection.You can use this to insert all the elements of a list into another list:
//before var list = [1, 2, 3]; var list2 = []; list2.addAll(list); //after var list = [1, 2, 3]; var list2 = [0, ...list];