Home > database >  Flutter, how to call/add/trigger others event inside same bloc
Flutter, how to call/add/trigger others event inside same bloc

Time:02-21

Flutter, how to call/add/trigger others event inside same bloc

I want to call refresh event after update database

mapEventToA("update database").then -> mapEventToB("refresh")

is it possible?

I just already have a refresh event so I want to reuse it

CodePudding user response:

If you want to call an event inside the same BLoC you can use the add method.

class MyBloc extends Bloc<MyEvent, MyState> {

 ...

 void _onSomeEvent(SomeEvent event, Emitter<MyState> emit){
   // Some logic
   ...

   // Call an event inside the BLoC
   add(const RefreshEvent());
 }
}
  • Related