We can then update the EventHandler
to handle the CounterIncrementPressed
event:
abstract class CounterEvent {}
class CounterIncrementPressed extends CounterEvent {}
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<CounterIncrementPressed>((event, emit) {
emit(state + 1);
});
}
}
In the above snippet, we have registered an EventHandler
to manage all CounterIncrementPressed
events. For each incoming CounterIncrementPressed
event we can access the current state of the bloc via the state
getter and emit(state + 1)
.