Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 596571b

Browse files
authored
[web] remove implicit casts and implicit dynamic (#27882)
1 parent 08cec9e commit 596571b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+283
-170
lines changed

lib/web_ui/analysis_options.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
include: ../../analysis_options.yaml
88

9-
analyzer:
10-
strong-mode:
11-
implicit-casts: true
12-
implicit-dynamic: true
13-
149
linter:
1510
rules:
1611
public_member_api_docs: false

lib/web_ui/lib/src/engine/assets.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AssetManager {
6161
final html.HttpRequest request =
6262
await html.HttpRequest.request(url, responseType: 'arraybuffer');
6363

64-
final ByteBuffer response = request.response;
64+
final ByteBuffer response = request.response as ByteBuffer;
6565
return response.asByteData();
6666
} on html.ProgressEvent catch (e) {
6767
final html.EventTarget? target = e.target;

lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,8 @@ class NotoDownloader {
969969
if (assertionsEnabled) {
970970
_debugActiveDownloadCount += 1;
971971
}
972-
final Future<ByteBuffer> result = html.window.fetch(url).then(
973-
(dynamic fetchResult) => fetchResult
972+
final Future<ByteBuffer> result = httpFetch(url).then(
973+
(html.Body fetchResult) => fetchResult
974974
.arrayBuffer()
975975
.then<ByteBuffer>((dynamic x) => x as ByteBuffer));
976976
if (assertionsEnabled) {
@@ -988,8 +988,8 @@ class NotoDownloader {
988988
if (assertionsEnabled) {
989989
_debugActiveDownloadCount += 1;
990990
}
991-
final Future<String> result = html.window.fetch(url).then(
992-
(dynamic response) =>
991+
final Future<String> result = httpFetch(url).then(
992+
(html.Body response) =>
993993
response.text().then<String>((dynamic x) => x as String));
994994
if (assertionsEnabled) {
995995
result.whenComplete(() {

lib/web_ui/lib/src/engine/canvaskit/fonts.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class SkiaFontCollection {
109109
}
110110

111111
final List<dynamic>? fontManifest =
112-
json.decode(utf8.decode(byteData.buffer.asUint8List()));
112+
json.decode(utf8.decode(byteData.buffer.asUint8List())) as List<dynamic>?;
113113
if (fontManifest == null) {
114114
throw AssertionError(
115115
'There was a problem trying to load FontManifest.json');
@@ -119,16 +119,16 @@ class SkiaFontCollection {
119119

120120
for (final Map<String, dynamic> fontFamily
121121
in fontManifest.cast<Map<String, dynamic>>()) {
122-
final String family = fontFamily['family']!;
123-
final List<dynamic> fontAssets = fontFamily['fonts'];
122+
final String family = fontFamily.readString('family');
123+
final List<dynamic> fontAssets = fontFamily.readList('fonts');
124124

125125
if (family == 'Roboto') {
126126
registeredRoboto = true;
127127
}
128128

129129
for (final dynamic fontAssetItem in fontAssets) {
130-
final Map<String, dynamic> fontAsset = fontAssetItem;
131-
final String asset = fontAsset['asset'];
130+
final Map<String, dynamic> fontAsset = fontAssetItem as Map<String, dynamic>;
131+
final String asset = fontAsset.readString('asset');
132132
_unloadedFonts
133133
.add(_registerFont(assetManager.getAssetUrl(asset), family));
134134
}
@@ -151,7 +151,7 @@ class SkiaFontCollection {
151151
Future<RegisteredFont?> _registerFont(String url, String family) async {
152152
ByteBuffer buffer;
153153
try {
154-
buffer = await html.window.fetch(url).then(_getArrayBuffer);
154+
buffer = await httpFetch(url).then(_getArrayBuffer);
155155
} catch (e) {
156156
printWarning('Failed to load font $family at $url');
157157
printWarning(e.toString());
@@ -178,8 +178,7 @@ class SkiaFontCollection {
178178
return actualFamily;
179179
}
180180

181-
Future<ByteBuffer> _getArrayBuffer(dynamic fetchResult) {
182-
// TODO(yjbanov): fetchResult.arrayBuffer is a dynamic invocation. Clean it up.
181+
Future<ByteBuffer> _getArrayBuffer(html.Body fetchResult) {
183182
return fetchResult
184183
.arrayBuffer()
185184
.then<ByteBuffer>((dynamic x) => x as ByteBuffer);

lib/web_ui/lib/src/engine/canvaskit/initialization.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void _startDownloadingCanvasKit(String? canvasKitBase) {
179179

180180
// First check if `exports` and `module` are already defined. If so, then
181181
// CommonJS is being used, and we shouldn't have any problems.
182-
final js.JsFunction objectConstructor = js.context['Object'];
182+
final js.JsFunction objectConstructor = js.context['Object'] as js.JsFunction;
183183
if (js.context['exports'] == null) {
184184
final js.JsObject exportsAccessor = js.JsObject.jsify(<String, dynamic>{
185185
'get': js.allowInterop(() {

lib/web_ui/lib/src/engine/canvaskit/layer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class TransformEngineLayer extends ContainerLayer
361361

362362
@override
363363
void preroll(PrerollContext prerollContext, Matrix4 matrix) {
364-
final Matrix4 childMatrix = matrix * _transform;
364+
final Matrix4 childMatrix = matrix.multiplied(_transform);
365365
prerollContext.mutatorsStack.pushTransform(_transform);
366366
final ui.Rect childPaintBounds = prerollChildren(prerollContext, childMatrix);
367367
paintBounds = transformRect(_transform, childPaintBounds);

lib/web_ui/lib/src/engine/canvaskit/text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ class CkParagraph extends SkiaObject<SkParagraph> implements ui.Paragraph {
725725
final List<ui.TextBox> result = <ui.TextBox>[];
726726

727727
for (int i = 0; i < skRects.length; i++) {
728-
final List<double> rect = skRects[i];
728+
final List<double> rect = skRects[i] as List<double>;
729729
result.add(ui.TextBox.fromLTRBD(
730730
rect[0],
731731
rect[1],

lib/web_ui/lib/src/engine/clipboard.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ClipboardMessageHandler {
2525
const MethodCodec codec = JSONMethodCodec();
2626
bool errorEnvelopeEncoded = false;
2727
_copyToClipboardStrategy
28-
.setData(methodCall.arguments['text'])
28+
.setData(methodCall.arguments['text'] as String?)
2929
.then((bool success) {
3030
if (success) {
3131
callback!(codec.encodeSuccessEnvelope(true));

lib/web_ui/lib/src/engine/dom_renderer.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ class DomRenderer {
115115
/// See for more details:
116116
/// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus
117117
bool get windowHasFocus =>
118-
js_util.callMethod(html.document, 'hasFocus', <dynamic>[]) ?? false;
118+
js_util.callMethod(html.document, 'hasFocus', <dynamic>[]) as bool;
119119

120120
void _setupHotRestart() {
121121
// This persists across hot restarts to clear stale DOM.
122122
_staleHotRestartState =
123-
js_util.getProperty(html.window, _staleHotRestartStore);
123+
js_util.getProperty(html.window, _staleHotRestartStore) as List<html.Element?>?;
124124
if (_staleHotRestartState == null) {
125125
_staleHotRestartState = <html.Element?>[];
126126
js_util.setProperty(
@@ -238,7 +238,10 @@ class DomRenderer {
238238

239239
static void setElementTransform(html.Element element, String transformValue) {
240240
js_util.setProperty(
241-
js_util.getProperty(element, 'style'), 'transform', transformValue);
241+
js_util.getProperty(element, 'style') as Object,
242+
'transform',
243+
transformValue,
244+
);
242245
}
243246

244247
void setText(html.Element element, String text) {
@@ -571,7 +574,7 @@ class DomRenderer {
571574
return Future<bool>.value(true);
572575
} else {
573576
final String? lockType =
574-
_deviceOrientationToLockType(orientations.first);
577+
_deviceOrientationToLockType(orientations.first as String?);
575578
if (lockType != null) {
576579
final Completer<bool> completer = Completer<bool>();
577580
try {

lib/web_ui/lib/src/engine/html/offscreen_canvas.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ class OffScreenCanvas {
6969
0, 0, width, height]);
7070
}
7171

72-
/// Converts canvas contents to an image and returns as data url.
72+
/// Converts canvas contents to an image and returns as data URL.
7373
Future<String> toDataUrl() {
7474
final Completer<String> completer = Completer<String>();
7575
if (offScreenCanvas != null) {
7676
offScreenCanvas!.convertToBlob().then((html.Blob value) {
7777
final html.FileReader fileReader = html.FileReader();
7878
fileReader.onLoad.listen((html.ProgressEvent event) {
79-
completer.complete(js_util.getProperty(
80-
js_util.getProperty(event, 'target')!, 'result')!);
79+
completer.complete(
80+
js_util.getProperty(js_util.getProperty(event, 'target') as Object, 'result') as String,
81+
);
8182
});
8283
fileReader.readAsDataUrl(value);
8384
});

0 commit comments

Comments
 (0)