Ara Hussein
Ara Hussein

Reputation: 280

2 dots and three dots in flutter

what does the 2 dots mean in dart like this one when you want to create a Paint:

var paint = Paint()
..shader = gradient.createShader(rect)

and the 3 dots like this sample I saw it in flutter sample

ListView(
        children: [
          ListTile(title: Text('Basics', style: headerStyle)),
          ...basicDemos.map((d) => DemoTile(d)),
          ListTile(title: Text('Misc', style: headerStyle)),
          ...miscDemos.map((d) => DemoTile(d)),
        ],
      ),

Upvotes: 4

Views: 2221

Answers (1)

rid
rid

Reputation: 63540

Two dots (..) is the syntax for cascade notation:

var button = querySelector('#confirm');
button.text = 'Confirm';
button.classes.add('important');
button.onClick.listen((e) => window.alert('Confirmed!'));

can be rewritten to:

querySelector('#confirm')
  ..text = 'Confirm'
  ..classes.add('important')
  ..onClick.listen((e) => window.alert('Confirmed!'));

Three dots (...) is the spread operator:

var list = [1, 2, 3];
var list2 = [0, ...list];

list2 contains [0, 1, 2, 3].

Upvotes: 9

Related Questions