728x90

 

Flutter의 Dart에서 함수 호출시 ".." 을 사용하는 경우가 있다.

이는 동일한 객체에 대해 여러 메소드를 호출하려할 때 간략하게 쓰는 것임.

즉, 동일한 타겟을 반복하지 않아도 되도록 하는 것

ex)
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);
//It's the cascade operator of Dart

var l1 = new List<int>()..add(0)..addAll([1, 2, 3]);

//results in l1 being a list [0, 1, 2, 3]

var l1 = new List<int>().add(0).addAll([1, 2, 3]);

 

 

results in an error, because .add(0) returns void

.. (in the former example) refers to new List(), while . (in the later) refers to the return value of the previous part of the expression.

.. was introduced to avoid the need to return this in all kinds of methods like add() to be able to use an API in a fluent way.

.. provides this out of the box for all classes.

 

 

Reference

stackoverflow.com/questions/49447736/list-use-of-double-dot-in-dart

 

List use of double dot (.) in dart?

Sometimes I see this List list = []; Then list..add(color) Whats the difference in using 1 dot(.) and 2 dot(..)?

stackoverflow.com

 

728x90

'Dev > Flutter' 카테고리의 다른 글

[Flutter/web] Platform 함수 에러 관련  (0) 2021.01.15
[Flutter] 플러터로 Web하기  (0) 2020.09.07

+ Recent posts