A flutter package that handles listening and publishing events throughout your app, with the observer pattern.
Features
- Publish events
- Listen to all events
- Listen to specific types of events
Getting started
- Go inside your pubspec.yaml file
- Add this line under the dependencies:
flutter_fit_events: ^1.0.3
- Get dependencies
flutter pub get
Usage
First, AppEventsDispatcher is a Singleton, so you can use it easily everywhere.
- Send an event for dispatch with
AppEventsDispatcher().publish(event)
- Listen to all events with
AppEventsDispatcher().stream.listen((AppEvent event) {})
- Listen to a specific type of event with
AppEventsDispatcher().listenTo<AppEventType>((AppEvent event) {})
You can create your own events by extending the AppEvent
class.
For signaling errors, you can directly use the ErrorEvent
class or extend it to create your own error event.
Additional information
Inspired from this article. Feel free to give any feedback ! This package is also open to contributions.