简体   繁体   English

Flutter Bloc,什么是“..add”

[英]Flutter Bloc, what is the "..add"

create: (_) {
            return NewCarBloc(newCarRepository: NewCarRepository())
                ..add(NewCarFormLoaded());
          }

Why it has 2 dots here?为什么这里有2个点?

Why not like below?为什么不喜欢下面? I tried in various ways, but nothing else works.我尝试了各种方法,但没有其他方法。

create: (_) {
            return NewCarBloc(newCarRepository: NewCarRepository())
                .add(NewCarFormLoaded());
          }

The double dot operator let you call multiple functions on the same object in one instruction.双点运算符让您可以在一条指令中调用同一个 object 上的多个函数。 It's named cascade operator.它被命名为级联运算符。

For more about cascade operator: https://fluttermaster.com/method-chaining-using-cascade-in-dart/有关级联运算符的更多信息: https://fluttermaster.com/method-chaining-using-cascade-in-dart/

Here your first function is to create the object and the second is "add" function.在这里,您的第一个 function 是创建 object,第二个是“添加”function。

If you don't want to use cascade operator you can do this like so:如果您不想使用级联运算符,您可以这样做:

create: (_) {
        NewCarBloc newCarBloc = NewCarBloc(newCarRepository: NewCarRepository());
        return newCarBlock.add(NewCarFormLoaded());
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM