off method
Removes callback from event, or every callback of this client when
it is null. Only this client's own JS bridge is detached -- listeners
that other code put on the same WPP event stay.
Implementation
@override
Future<void> off(String event, [Function(dynamic)? callback]) async {
final handlers = _listeners[event];
if (handlers == null) return;
if (callback != null) {
handlers.remove(callback);
} else {
handlers.clear();
}
if (handlers.isNotEmpty) return;
_listeners.remove(event);
controller?.removeJavaScriptHandler(handlerName: _handlerName(event));
final e = jsonEncode(event);
await evaluateJs(
'''(function() {
var l = window.__dragoListeners;
if (!l || !l[$e]) return;
if (window.WPP) window.WPP.off($e, l[$e]);
delete l[$e];
})();''',
tryPromise: false,
);
}