diff --git a/examples/misc/lib/library_tour/async/stream_web.dart b/examples/misc/lib/library_tour/async/stream_web.dart index b9a143eb16..1c8e8b4e43 100644 --- a/examples/misc/lib/library_tour/async/stream_web.dart +++ b/examples/misc/lib/library_tour/async/stream_web.dart @@ -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) { diff --git a/examples/type_system/lib/common_fixes_analysis.dart b/examples/type_system/lib/common_fixes_analysis.dart index 0c7d2cb035..8353181af1 100644 --- a/examples/type_system/lib/common_fixes_analysis.dart +++ b/examples/type_system/lib/common_fixes_analysis.dart @@ -1,17 +1,17 @@ // 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 @@ -19,14 +19,14 @@ void _samplesFromCommonProblemsPage() { { // #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 } diff --git a/examples/type_system/pubspec.yaml b/examples/type_system/pubspec.yaml index a9d9b21823..6a65c8140c 100644 --- a/examples/type_system/pubspec.yaml +++ b/examples/type_system/pubspec.yaml @@ -7,6 +7,7 @@ environment: dependencies: examples_util: {path: ../util} + web: ^1.1.0 dev_dependencies: test: ^1.25.8 diff --git a/src/content/deprecated/sound-problems.md b/src/content/deprecated/sound-problems.md index 339d460f9c..ce2c63053a 100644 --- a/src/content/deprecated/sound-problems.md +++ b/src/content/deprecated/sound-problems.md @@ -99,7 +99,7 @@ In the following code, the analyzer complains that `context2D` is undefined: ```dart tag=fails-sa -var canvas = querySelector('canvas')!; +var canvas = document.querySelector('canvas')!; canvas.[!context2D!].lineTo(x, y); ``` @@ -121,15 +121,15 @@ You can fix this error with an explicit downcast: ```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: ```dart tag=passes-sa -[!dynamic!] canvasOrImg = querySelector('canvas, img'); +var canvasOrImg = document.querySelector('canvas, img') as [!dynamic!]; var width = canvasOrImg.width; ```