Warm tip: This article is reproduced from stackoverflow.com, please click
dart

List use of double dot (.) in dart?

发布于 2020-03-29 12:47:50

Sometimes I see this List list = [];

Then list..add(color)

Whats the difference in using 1 dot(.) and 2 dot(..)?

Questioner
Daniel Mana
Viewed
74
Alexandre Ardhuin 2018-03-23 18:44

.. is known as cascade notation. It allows you to not repeat the same target if you want to call several methods on the same object.

List list = [];
list.add(color1);
list.add(color2);
list.add(color3);
list.add(color4);

// with cascade

List list = [];
list
  ..add(color1)
  ..add(color2)
  ..add(color3)
  ..add(color4);