Event<T> class
Generic event system for handling typed events with multiple listeners.
This class provides a flexible event system that supports both synchronous and asynchronous listeners. Events can be emitted with typed data, and all registered listeners will be called in the order they were added.
Features:
- Type-safe event data
- Support for both sync and async listeners
- Sequential execution of listeners
- Return count of executed listeners
Example:
var userCreated = Event<User>();
userCreated.addListener((user) {
print('User created: ${user.name}');
});
userCreated.addAsyncListener((user) async {
await sendWelcomeEmail(user);
});
await userCreated.emit(newUser);
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addAsyncListener(
EventAsyncFunction listener) → Event - Adds an asynchronous listener to the event.
-
addListener(
EventFunction listener) → Event - Adds a synchronous listener to the event.
-
emit(
[dynamic data]) → Future< int> - Emits the event, calling all registered listeners.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited