bloc_event 1.0.6
bloc_event: ^1.0.6

Dart native js
Flutter Android iOS web

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 #

To use this plugin, add bloc_event as a dependency in your pubspec.yaml file.

Basic Usage #

Create your events base class like followed:

abstract class MyEvent extends Event<MyBloc, MyState> {}

Your actual Event should look like:

class DoSomethingEvent extends MyEvent {
  final String myData;
  
  DoSomethingEvent(this.myData);
  
  @Override
  Stream<MyState> onTriggered(MyBloc bloc, MyState state) async* {
    // Do your event stuff here
    yield state.copyWith(data: myData);
  }
}

By extending EventBloc in your Bloc you don't have to implement mapEventToState:

class MyBloc extends EventBloc<MyEvent, MyState> {
  
  @Override
  MyState get initialState => MyState();
  
}

That's it!!

Testing #

You are now able to test your events separated easily without even using the bloc.

test('sample test', () {
    var myEventToTest = MyEvent(myData);
    var result = myEventToTest.onTriggered(myMockedBloc, myCurrentState);
    expectLater(result, emits(myNewState));
});
3
likes
80
pub points
23%
popularity

Publisher

ownii.com

With this package you can define the logic that an bloc event executes inside the events class.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

bloc

More

Packages that depend on bloc_event