OLD | NEW |
(Empty) | |
| 1 import 'dart:async'; |
| 2 import 'dart:html'; |
| 3 |
| 4 void main() { |
| 5 // Get a stream of key-press events from an element: |
| 6 querySelector('textarea').onKeyPress |
| 7 |
| 8 // Filter the stream, getting a stream of events only for certain key codes: |
| 9 .where((e) => e.keyCode >= 32 && e.keyCode <= 122) |
| 10 |
| 11 // Convert those key codes, getting a stream of corresponding characters: |
| 12 .map((e) => new String.fromCharCode(e.charCode)) |
| 13 |
| 14 // Ask for the first character, getting a Future. |
| 15 .first |
| 16 |
| 17 // When the Future completes, print the first character to the console. |
| 18 .then((char) => print('First char=$char')); |
| 19 } |
OLD | NEW |