unsubscribe<T> method
Unsubscribe from the given topic. Your handler will no longer recieve events published to this topic
topic
The topic to unsubscribe fromhandler
The event handler
Implementation
unsubscribe<T>(String topic, {EventHandler<T>? handler}) {
if (handler == null) {
_callbackMaps.remove(topic);
return;
}
final handlers = _callbackMaps[topic];
if (handlers == null) {
return;
}
// We now need to remove specific handler
final handlerIndex = handlers.indexOf(handler);
if (handlerIndex >= 0) {
handlers.removeAt(handlerIndex);
if (handlers.length == 0) {
_callbackMaps.remove(topic);
}
}
}