OLD | NEW |
(Empty) | |
| 1 import 'dart:html'; |
| 2 |
| 3 main() async { |
| 4 const findMe = 'jabberwock'; |
| 5 |
| 6 // Find an element with the ID "jw". |
| 7 var displayer = querySelector('#jw'); |
| 8 |
| 9 // Get the text to display, and display it. |
| 10 var lines = await getLines(findMe); |
| 11 lines?.forEach((line) { |
| 12 print(line); |
| 13 displayer?.text += line + '\n'; |
| 14 }); |
| 15 |
| 16 // Find all elements with the class "searchString". |
| 17 querySelectorAll('.searchString').forEach((el) { |
| 18 // Set each one's text and highlight it. |
| 19 el..text = findMe |
| 20 ..classes.add('highlighted'); |
| 21 }); |
| 22 } |
| 23 |
| 24 // Reads a file, returning its lines. |
| 25 getLines(String withString) async { |
| 26 var jabber = await HttpRequest.getString( |
| 27 'https://www.dartlang.org/samples-files/jabberwocky.txt'); |
| 28 var lines = jabber.split('\n'); |
| 29 lines.retainWhere((line) => |
| 30 line.toLowerCase().contains(withString)); |
| 31 return lines; |
| 32 } |
OLD | NEW |