EventSystemInterface class abstract
Core event system contract for managing listeners, emitting events, and groups.
This interface provides a flexible pub-sub system for decoupling components. Implementations should ensure thread-safety if used in concurrent environments.
Key features:
- Register listeners with priorities and one-time execution.
- Group events for batch operations.
- Emit events synchronously or asynchronously.
- Manage subscriptions per subscriber for easy cleanup.
Example usage:
class MyEventSystem implements EventSystemInterface {
// Implementation here
}
final events = MyEventSystem();
events.on('user.created', (user) => print('User: $user'));
await events.emit('user.created', {'id': 1, 'name': 'Alice'});
- Implementers
- Annotations
-
- @Deprecated('Use Dispatcher interface instead')
Constructors
Properties
-
eventGroups
→ Map<
String, Set< String> > -
Internal map of group names to sets of event names.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
listeners
→ Map<
String, List< EventRegistration> > -
Internal map of event names to their registered listeners.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
subscriberEvents
→ Map<
Object, Set< String> > -
Internal map tracking events registered by each subscriber for cleanup.
final
Methods
-
addToGroup(
String groupName, String event) → void - Adds an event to a named group for batch operations.
-
clear(
) → void - Clears all listeners, event groups, and subscriber tracking.
-
emit(
String event, [dynamic payload, bool queue = false]) → Future< void> - Emits an event to all its registered listeners.
-
emitGroup(
String groupName, [dynamic payload, bool queue = false]) → Future< void> - Emits all events within a named group.
-
hasListeners(
String event) → bool - Checks if any listeners are registered for the event.
-
listenerCount(
String event) → int - Returns the number of listeners registered for the event.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
off(
String event, EventListener listener) → void - Removes a specific listener from an event.
-
offEvent(
String event) → void - Removes all listeners for a specific event.
-
offSubscriber(
Object subscriber) → void - Removes all events registered by a specific subscriber.
-
on(
String event, EventListener listener, {EventPriority priority = EventPriority.normal, bool once = false, Object? subscriber}) → void - Registers a listener for a specific event.
-
once(
String event, EventListener listener, {EventPriority priority = EventPriority.normal, Object? subscriber}) → void - Registers a one-time listener for a specific event.
-
removeFromGroup(
String groupName, String event) → void - Removes an event from a named group.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited