Skip to content

Commit

Permalink
Remove dart:html from more excerpt sources (#6394)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Feb 6, 2025
1 parent 7d4409c commit 5808b1a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/misc/lib/library_tour/async/stream_web.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:html';
import 'package:web/web.dart' as web;

void miscDeclAnalyzedButNotTested() {
{
void submitData() {}
var submitButton = querySelector('#submitInfo')!;
var submitButton = web.document.querySelector('#submitInfo')!;
// #docregion listen
// Add an event handler to a button.
submitButton.onClick.listen((e) {
Expand Down
12 changes: 6 additions & 6 deletions examples/type_system/lib/common_fixes_analysis.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// NOTE: Declarations in this file are analyzed but not tested.
// ignore_for_file: unused_element, unused_local_variable, one_member_abstracts, use_super_parameters
// ignore_for_file: prefer_function_declarations_over_variables, unused_field, strict_raw_type, deprecated_member_use
// ignore_for_file: prefer_function_declarations_over_variables, unused_field, strict_raw_type

import 'dart:html';
import 'package:web/web.dart';

// Include in this file only excerpts used to illustrate fixes to common problems.
// Excerpts used to illustrate potential fixes to common type problems.
void _samplesFromCommonProblemsPage() {
final double x = 0;
final double y = 0;

{
// #docregion canvas-undefined
var canvas = querySelector('canvas')!;
var canvas = document.querySelector('canvas')!;
// ignore: stable, beta, dev, undefined_getter
canvas.context2D.lineTo(x, y);
// #enddocregion canvas-undefined
}

{
// #docregion canvas-as
var canvas = querySelector('canvas') as CanvasElement;
var canvas = document.querySelector('canvas') as HTMLCanvasElement;
canvas.context2D.lineTo(x, y);
// #enddocregion canvas-as
}

{
// #docregion canvas-dynamic
dynamic canvasOrImg = querySelector('canvas, img');
var canvasOrImg = document.querySelector('canvas, img') as dynamic;
var width = canvasOrImg.width;
// #enddocregion canvas-dynamic
}
Expand Down
1 change: 1 addition & 0 deletions examples/type_system/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ environment:

dependencies:
examples_util: {path: ../util}
web: ^1.1.0

dev_dependencies:
test: ^1.25.8
8 changes: 4 additions & 4 deletions src/content/deprecated/sound-problems.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ In the following code, the analyzer complains that `context2D` is undefined:

<?code-excerpt "lib/common_fixes_analysis.dart (canvas-undefined)" replace="/context2D/[!$&!]/g"?>
```dart tag=fails-sa
var canvas = querySelector('canvas')!;
var canvas = document.querySelector('canvas')!;
canvas.[!context2D!].lineTo(x, y);
```

Expand All @@ -121,15 +121,15 @@ You can fix this error with an explicit downcast:

<?code-excerpt "lib/common_fixes_analysis.dart (canvas-as)" replace="/as \w+/[!$&!]/g"?>
```dart tag=passes-sa
var canvas = querySelector('canvas') [!as CanvasElement!];
var canvas = document.querySelector('canvas') [!as HTMLCanvasElement!];
canvas.context2D.lineTo(x, y);
```

Otherwise, use `dynamic` in situations where you cannot use a single type:
Otherwise, use `dynamic` in situations where you can't use a single type:

<?code-excerpt "lib/common_fixes_analysis.dart (canvas-dynamic)" replace="/dynamic/[!$&!]/g"?>
```dart tag=passes-sa
[!dynamic!] canvasOrImg = querySelector('canvas, img');
var canvasOrImg = document.querySelector('canvas, img') as [!dynamic!];
var width = canvasOrImg.width;
```

Expand Down

0 comments on commit 5808b1a

Please sign in to comment.