3
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());
          }
dontknowhy
  • 2,480
  • 2
  • 23
  • 67

1 Answers1

2

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());
      }
Milvintsiss
  • 1,420
  • 1
  • 18
  • 34
  • Hi. So, is there no way to just call "add event" normally except for ".." operator? for me, It feels little more complicated. – dontknowhy Jan 15 '21 at 06:21