Reputation: 2866
create: (_) {
return NewCarBloc(newCarRepository: NewCarRepository())
..add(NewCarFormLoaded());
}
Why it has 2 dots here?
Why not like below? I tried in various ways, but nothing else works.
create: (_) {
return NewCarBloc(newCarRepository: NewCarRepository())
.add(NewCarFormLoaded());
}
Upvotes: 3
Views: 1608
Reputation: 1448
The double dot operator let you call multiple functions on the same object in one instruction. It's named cascade operator.
For more about cascade operator: https://fluttermaster.com/method-chaining-using-cascade-in-dart/
Here your first function is to create the object and the second is "add" 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());
}
Upvotes: 2