Event<T extends EventArgs> class

Represents an Event as some number of handlers (subscribers) that can be notified when a condition occurs, by using the broadcast method.

See also EventArgs.

=====

// An example of a simple [Event] with no argument.
final onValueChanged = Event();
counter.onValueChanged + (_) => print('changed'); // add a handler
onValueChanged.broadcast(); // broadcast the [Event] to subscribers

// An example of an [Event] expecting an argument (see [EventArgs]).
final onValueChanged = Event<ChangedValue>();
counter.onValueChanged + (args) => print(args.changedValue); // add a handler
onValueChanged.broadcast(ChangedValue(37)); // broadcast the [Event] to subscribers

Constructors

Event()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
subscriberCount int
Returns the number of handlers (subscribers).
no setter

Methods

broadcast([T? args]) → void
Broadcast this Event to subscribers, with an optional EventArgs derived argument.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
subscribe(EventHandler<T> handler) → void
Adds a handler (callback) that will be executed when this Event is raised using the broadcast method.
subscribeStream(StreamSink sink) → void
Subscribes a Stream StreamSink to an Event.
toString() String
Represent this Event as its Type name
override
unsubscribe(EventHandler<T> handler) bool
Removes a handler previously added to this Event.
unsubscribeAll() → void
Removes all subscribers (handlers).

Operators

operator +(EventHandler<T> handler) → void
Adds a handler (callback) that will be executed when this Event is raised using the broadcast method.
operator -(EventHandler<T> handler) bool
Removes a handler previously added to this Event.
operator ==(Object other) bool
The equality operator.
inherited