What does that 2 dots mean? What is the difference between 1 and 2?

后端 未结 2 446
情深已故
情深已故 2021-01-11 17:20

I have seen a lot of tutorials using dot, while some use 2. What is the actual meaning of this?

Example,

Array().add()

Animation()..addListener(() {         


        
2条回答
  •  误落风尘
    2021-01-11 17:41

    The .. operator is dart "cascade" operator. Useful for chaining operations when you don't care about the return value. This is also dart solution to chainable functions that always return this

    It is made so that the following

    final foo = Foo()
     ..first()
     ..second();
    

    Is strictly equals to this:

    final foo = Foo();
    foo.first():
    foo.second();
    

提交回复
热议问题