Created
September 7, 2020 17:25
-
-
Save graphicbeacon/5a442c5045fb395bfb9b4984c8fc0012 to your computer and use it in GitHub Desktop.
Dispatching custom events example for Dart Web projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="text" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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