Bỏ qua để đến nội dung

Cascade Notation (..)

🎯 Mục tiêu: Chain operations trên cùng object.


var button = Button()
..text = "Click me"
..color = Colors.blue
..onClick = handleClick;
// Tương đương
var button = Button();
button.text = "Click me";
button.color = Colors.blue;
button.onClick = handleClick;

var list = <int>[]
..add(1)
..add(2)
..add(3)
..shuffle();

Button? button;
button
?..text = "Click"
..color = Colors.red;

final controller = TextEditingController()
..text = "Initial"
..selection = TextSelection.collapsed(offset: 0)
..addListener(() => print("Changed"));

  • .. returns the object, not the result
  • Useful for builders/initialization
  • ?.. for nullable objects