on method

Future<void> on(
  1. String eventName,
  2. JavaScriptBridgeEventCallback callback
)

Registers a Dart listener for events emitted by JavaScript.

Call this after the WebView is ready to evaluate JavaScript, such as in onLoadStop. The existing platform-ready event is still required before page JavaScript calls the bridge.

Implementation

Future<void> on(
  String eventName,
  JavaScriptBridgeEventCallback callback,
) async {
  _validateEventName(eventName);
  final listeners = _listeners.putIfAbsent(eventName, () => []);
  if (!listeners.contains(callback)) {
    listeners.add(callback);
  }
  await _ensureInstalled();
}