UseEvent<T extends Object?> class

A hook that manages events.

Allows to handle event of instance wherever. Using it with the instance directly:

UseEvent.withInstance(appController);

or using it with T instance that it to has been registed with ReactterInstanceManager:

UseEvent<AppController>();

if it has a id:

UseEvent<AppController>('uniqueId');

You can listen to event using on method:

enum Events { SomeEvent };

void _onSomeEvent(inst, param) {
  print("$inst's Events.SomeEvent emitted with param: $param.");
}

UseEvent<AppController>().on(Events.SomeEvent, _onSomeEvent);

use off method to stop listening event:

UseEvent<AppController>().off(Events.SomeEvent, _onSomeEvent);

If you want to listen to event only once, use one method:

UseEvent<AppController>().one(Events.SomeEvent, _onSomeEvent);

And use emit method to trigger event:

UseEvent<AppController>().emit(Events.SomeEvent, 'Parameter');

IMPORTANT: Don't forget to remove event using off or using dispose to remove all instance's events. Failure to do so could increase memory usage or have unexpected behaviors such as events in permanent listening.

See also:

Annotations
  • @Deprecated('Use event shortcuts instead. ' 'This feature was deprecated after v6.0.0-pre.')

Constructors

UseEvent([String? id])
UseEvent.withInstance(T instance)

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

dispose() → void
Removes all instance's events
emit(Enum eventName, [dynamic param]) → void
Triggers eventName event with or without the param given.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
off<P>(Enum eventName, CallbackEvent<T, P> callback) → void
Removes the callback of eventName event.
on<P extends dynamic>(Enum eventName, CallbackEvent<T, P> callback) → void
Puts on to listen eventName event.
one<P>(Enum eventName, CallbackEvent<T, P> callback) → void
Puts on to listen eventName event only once.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited