bloc_event 1.0.2 bloc_event: ^1.0.2 copied to clipboard
With this package you can define the logic that an bloc event executes inside the events class.
bloc_event #
Make the Bloc Events easier to structure
Getting Started #
Basic Usage #
Create your events base class like followed:
abstract class MyEvent<E> extends Event<MyBloc, MyState, E> {}
Your actual Event should look like:
class DoSomethingEvent extends MyEvent<DoSomethingEvent> {
final String myData;
DoSomethingEvent(this.myData);
@Override
Stream<MyState> onTriggered(MyBloc bloc, MyState currentState, DoSomethingEvent event) async* {
// Do your event stuff here
yield currentState.copyWith();
}
}
By extending EventBloc in your Bloc you don't have to implement mapEventToState:
class MyBloc extends EventBloc<MyEvent, MyState> {
@Override
MyState get initialState => MyState();
}
Thats it!!
Testing #
You are now able to test your events seperated easily without even using the bloc
example cooming soon