listen<T> method
NEW FEATURE
Listen for the event of type T
.
Requires MomentumState.
Example uses is for displaying dialogs, snackbars, and navigation.
It is highly recommended to only call this
inside MomentumState.initMomentumState.
NOTE: For dialogs/snackbars/toast/etc, this is better than
addListener because addListener only reacts to model.update(...)
which forces you to update your state where showing dialogs/snackbars/toast/etc
doesn't actually need it. With listen, You can send any kinds of data
to the widgets.
Implementation
void listen<T>({
required MomentumState state,
required void Function(T data) invoke,
}) {
var newHandler = MomentumEvent<T>(state);
newHandler.on().listen((data) {
invoke(data);
});
_eventHandlers.add(newHandler);
}