on method
Adds an event listener to this target with automatic Dart-to-JS callback conversion.
This is a convenience method that wraps listener using jsCallback
and calls addEventListener.
element.on('click', (e) {
print('Clicked!');
});
Implementation
void on(String type, void Function(web.Event) listener, [bool? useCapture]) {
// On the server, stubs.dart's EventTarget.addEventListener accepts dynamic callback
// On the browser, we need to convert the Dart function to a JS callback
final callback = js_callback.jsCallbackImpl(listener);
// Use the helper to handle platform-specific type conversion (e.g. .toJS)
js_callback.addEventListener(this, type, callback, useCapture);
}