Ad

Flutter, How To Call/add/trigger Others Event Inside Same Bloc

- 1 answer

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

Ad

Answer

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());
 }
}
Ad
source: stackoverflow.com
Ad