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(value)); // broadcast the [Event] to subscribers

Constructors

Event()

Properties

subscriberCount → int
Returns the number of handlers (subscribers). [...]
read-only
hashCode → int
The hash code for this object.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

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

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 ==(dynamic other) → bool
The equality operator.
inherited