Skip to content

Commit 316efff

Browse files
jsiedentopparlough
andauthored
Fix the code sample from dart web get started guide (#5688)
I have discovered that the dart web [get started](https://dart.dev/web/get-started) code example does not match the new dart:web interface. Therefore I have updated the documentation. Fixes: There is no specific issue, but it certainly helps #5674 and #5525 --------- Co-authored-by: Parker Lougheed <parlough@gmail.com>
1 parent d87db4f commit 316efff

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/content/web/get-started.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,28 @@ Let's customize the app you just created.
105105
It creates a new `LIElement` containing the specified `String`.
106106

107107
```dart
108-
Iterable<String> thingsTodo() sync* { ... }
108+
Iterable<String> thingsTodo() sync* { /* ... */ }
109109
110-
[!LIElement newLI(String itemText) => LIElement()..text = itemText;!]
111-
112-
void main() { ... }
110+
[!HTMLLIElement newLI(String itemText) =>!]
111+
[!(document.createElement('li') as HTMLLIElement)..text = itemText;!]
112+
113+
void main() { /* ... */ }
113114
```
114115

115-
3. In the `main()` function, initialize the `output` element using
116-
`thingsTodo()`:
116+
3. In the `main()` function, append content to the `output` element
117+
using `appendChild` and the values from `thingsTodo()`:
117118

118119
```dart
119-
Iterable<String> thingsTodo() sync* { ... }
120+
Iterable<String> thingsTodo() sync* { /* ... */ }
120121
121-
LIElement newLI(String itemText) => LIElement()..text = itemText;
122+
HTMLLIElement newLI(String itemText) =>
123+
(document.createElement('li') as HTMLLIElement)..text = itemText;
122124
123125
void main() {
124-
querySelector('#output')?[!.children.addAll(thingsTodo().map(newLI));!]
126+
final output = querySelector('#output');
127+
[!for (final item in thingsTodo()) {!]
128+
[!output?.appendChild(newLI(item));!]
129+
[!}!]
125130
}
126131
```
127132

0 commit comments

Comments
 (0)