Skip to content

Commit

Permalink
Fix the code sample from dart web get started guide (#5688)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jsiedentop and parlough committed Apr 9, 2024
1 parent d87db4f commit 316efff
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/content/web/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,28 @@ Let's customize the app you just created.
It creates a new `LIElement` containing the specified `String`.

```dart
Iterable<String> thingsTodo() sync* { ... }
Iterable<String> thingsTodo() sync* { /* ... */ }
[!LIElement newLI(String itemText) => LIElement()..text = itemText;!]
void main() { ... }
[!HTMLLIElement newLI(String itemText) =>!]
[!(document.createElement('li') as HTMLLIElement)..text = itemText;!]
void main() { /* ... */ }
```

3. In the `main()` function, initialize the `output` element using
`thingsTodo()`:
3. In the `main()` function, append content to the `output` element
using `appendChild` and the values from `thingsTodo()`:

```dart
Iterable<String> thingsTodo() sync* { ... }
Iterable<String> thingsTodo() sync* { /* ... */ }
LIElement newLI(String itemText) => LIElement()..text = itemText;
HTMLLIElement newLI(String itemText) =>
(document.createElement('li') as HTMLLIElement)..text = itemText;
void main() {
querySelector('#output')?[!.children.addAll(thingsTodo().map(newLI));!]
final output = querySelector('#output');
[!for (final item in thingsTodo()) {!]
[!output?.appendChild(newLI(item));!]
[!}!]
}
```

Expand Down

0 comments on commit 316efff

Please sign in to comment.