Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created September 7, 2020 17:25
Show Gist options
  • Save graphicbeacon/5a442c5045fb395bfb9b4984c8fc0012 to your computer and use it in GitHub Desktop.
Save graphicbeacon/5a442c5045fb395bfb9b4984c8fc0012 to your computer and use it in GitHub Desktop.
Dispatching custom events example for Dart Web projects
<input type="text" />
import 'dart:html';
void main() {
final input = querySelector('input');
input.onKeyPress.listen((data) {
final customKeypress = CustomEvent('keypress', detail: {
'keyCode': data.keyCode,
'charCode': data.charCode,
});
input.dispatchEvent(customKeypress);
});
input.on['keypress'].listen((data) {
print('Heyyy! ${(data as CustomEvent).detail['keyCode']}');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment