From f3be9f1bc46ec18cc2eb193598f1bb8173c75831 Mon Sep 17 00:00:00 2001 From: Srujan Gaddam <58529443+srujzs@users.noreply.github.com> Date: Fri, 10 Jul 2020 16:49:58 -0700 Subject: [PATCH] Incorporate compat info changes into flutter engine (#19606) Changes related to compatibility info require changes in Flutter engine libraries. This CL adds null-asserts wherever necessary to maintain behavior and adds some small modifications to handle the change in nullability. Warnings about unnecessary null assertions are disabled temporarily in this CL as well. Original issue: https://github.com/dart-lang/sdk/issues/41905 --- lib/web_ui/analysis_options.yaml | 2 + lib/web_ui/lib/src/engine/assets.dart | 2 +- lib/web_ui/lib/src/engine/bitmap_canvas.dart | 4 +- .../lib/src/engine/browser_detection.dart | 2 +- .../lib/src/engine/browser_location.dart | 4 +- lib/web_ui/lib/src/engine/clipboard.dart | 4 +- lib/web_ui/lib/src/engine/dom_renderer.dart | 6 +- lib/web_ui/lib/src/engine/keyboard.dart | 4 +- .../lib/src/engine/pointer_binding.dart | 64 +++++++++---------- .../src/engine/semantics/incrementable.dart | 8 +-- .../engine/semantics/semantics_helper.dart | 2 +- .../lib/src/engine/semantics/text_field.dart | 8 +-- lib/web_ui/lib/src/engine/surface/scene.dart | 4 +- .../lib/src/engine/surface/surface_stats.dart | 10 +-- .../lib/src/engine/text/font_collection.dart | 8 +-- .../lib/src/engine/text/measurement.dart | 2 +- lib/web_ui/lib/src/engine/window.dart | 28 ++++---- 17 files changed, 82 insertions(+), 80 deletions(-) diff --git a/lib/web_ui/analysis_options.yaml b/lib/web_ui/analysis_options.yaml index 869fffe973553..7451e410e9411 100644 --- a/lib/web_ui/analysis_options.yaml +++ b/lib/web_ui/analysis_options.yaml @@ -12,6 +12,8 @@ analyzer: missing_required_param: warning missing_return: warning native_function_body_in_non_sdk_code: ignore + unnecessary_non_null_assertion: ignore + unnecessary_null_comparison: ignore todo: ignore linter: diff --git a/lib/web_ui/lib/src/engine/assets.dart b/lib/web_ui/lib/src/engine/assets.dart index 60803b0d00560..16d45fd66e758 100644 --- a/lib/web_ui/lib/src/engine/assets.dart +++ b/lib/web_ui/lib/src/engine/assets.dart @@ -64,7 +64,7 @@ class AssetManager { .warn('Asset manifest does not exist at `$url` – ignoring.'); return Uint8List.fromList(utf8.encode('{}')).buffer.asByteData(); } - throw AssetManagerException(url, target.status); + throw AssetManagerException(url, target.status!); } html.window.console.warn('Caught ProgressEvent with target: $target'); diff --git a/lib/web_ui/lib/src/engine/bitmap_canvas.dart b/lib/web_ui/lib/src/engine/bitmap_canvas.dart index b594f39ed665f..39005e3981b6f 100644 --- a/lib/web_ui/lib/src/engine/bitmap_canvas.dart +++ b/lib/web_ui/lib/src/engine/bitmap_canvas.dart @@ -364,7 +364,7 @@ class BitmapCanvas extends EngineCanvas { } html.ImageElement _reuseOrCreateImage(HtmlImage htmlImage) { - final String cacheKey = htmlImage.imgElement.src; + final String cacheKey = htmlImage.imgElement.src!; if (_elementCache != null) { html.ImageElement? imageElement = _elementCache!.reuse(cacheKey) as html.ImageElement?; if (imageElement != null) { @@ -674,7 +674,7 @@ class BitmapCanvas extends EngineCanvas { for (int i = 0; i < len; i++) { final String char = line.displayText![i]; ctx!.fillText(char, x, y); - x += letterSpacing + ctx.measureText(char).width; + x += letterSpacing + ctx.measureText(char).width!; } } } diff --git a/lib/web_ui/lib/src/engine/browser_detection.dart b/lib/web_ui/lib/src/engine/browser_detection.dart index 20fdb7f0fb010..394e98a55d743 100644 --- a/lib/web_ui/lib/src/engine/browser_detection.dart +++ b/lib/web_ui/lib/src/engine/browser_detection.dart @@ -115,7 +115,7 @@ OperatingSystem get operatingSystem { OperatingSystem? debugOperatingSystemOverride; OperatingSystem _detectOperatingSystem() { - final String platform = html.window.navigator.platform; + final String platform = html.window.navigator.platform!; final String userAgent = html.window.navigator.userAgent; if (platform.startsWith('Mac')) { diff --git a/lib/web_ui/lib/src/engine/browser_location.dart b/lib/web_ui/lib/src/engine/browser_location.dart index 2bbe9ec47c8d0..43b0e14b4f57a 100644 --- a/lib/web_ui/lib/src/engine/browser_location.dart +++ b/lib/web_ui/lib/src/engine/browser_location.dart @@ -176,10 +176,10 @@ class BrowserPlatformLocation extends PlatformLocation { } @override - String get pathname => _location.pathname; + String get pathname => _location.pathname!; @override - String get search => _location.search; + String get search => _location.search!; @override String get hash => _location.hash; diff --git a/lib/web_ui/lib/src/engine/clipboard.dart b/lib/web_ui/lib/src/engine/clipboard.dart index f9446b68a2e60..783c78d2aa564 100644 --- a/lib/web_ui/lib/src/engine/clipboard.dart +++ b/lib/web_ui/lib/src/engine/clipboard.dart @@ -109,7 +109,7 @@ class ClipboardAPICopyStrategy implements CopyToClipboardStrategy { @override Future setData(String? text) async { try { - await html.window.navigator.clipboard.writeText(text!); + await html.window.navigator.clipboard!.writeText(text!); } catch (error) { print('copy is not successful $error'); return Future.value(false); @@ -127,7 +127,7 @@ class ClipboardAPICopyStrategy implements CopyToClipboardStrategy { class ClipboardAPIPasteStrategy implements PasteFromClipboardStrategy { @override Future getData() async { - return html.window.navigator.clipboard.readText(); + return html.window.navigator.clipboard!.readText(); } } diff --git a/lib/web_ui/lib/src/engine/dom_renderer.dart b/lib/web_ui/lib/src/engine/dom_renderer.dart index 19fefdd89f3fe..850562a2c46b0 100644 --- a/lib/web_ui/lib/src/engine/dom_renderer.dart +++ b/lib/web_ui/lib/src/engine/dom_renderer.dart @@ -420,7 +420,7 @@ flt-glass-pane * { // Firefox returns correct values for innerHeight, innerWidth. // Firefox also triggers html.window.onResize therefore we don't need this // timer setup for Firefox. - final int initialInnerWidth = html.window.innerWidth; + final int initialInnerWidth = html.window.innerWidth!; // Counts how many times we checked screen size. We check up to 5 times. int checkCount = 0; Timer.periodic(const Duration(milliseconds: 100), (Timer t) { @@ -534,10 +534,10 @@ flt-glass-pane * { /// /// See w3c screen api: https://www.w3.org/TR/screen-orientation/ Future setPreferredOrientation(List? orientations) { - final html.Screen screen = html.window.screen; + final html.Screen screen = html.window.screen!; if (!_unsafeIsNull(screen)) { final html.ScreenOrientation screenOrientation = - screen.orientation; + screen.orientation!; if (!_unsafeIsNull(screenOrientation)) { if (orientations!.isEmpty) { screenOrientation.unlock(); diff --git a/lib/web_ui/lib/src/engine/keyboard.dart b/lib/web_ui/lib/src/engine/keyboard.dart index df1e5d6b66b01..0a37f7a01cb7d 100644 --- a/lib/web_ui/lib/src/engine/keyboard.dart +++ b/lib/web_ui/lib/src/engine/keyboard.dart @@ -89,7 +89,7 @@ class Keyboard { event.preventDefault(); } - final String timerKey = keyboardEvent.code; + final String timerKey = keyboardEvent.code!; // Don't synthesize a keyup event for modifier keys because the browser always // sends a keyup event for those. @@ -181,7 +181,7 @@ int _getMetaState(html.KeyboardEvent event) { /// Modifier keys are shift, alt, ctrl and meta/cmd/win. These are the keys used /// to perform keyboard shortcuts (e.g. `cmd+c`, `cmd+l`). bool _isModifierKey(html.KeyboardEvent event) { - final String key = event.key; + final String key = event.key!; return key == 'Meta' || key == 'Shift' || key == 'Alt' || key == 'Control'; } diff --git a/lib/web_ui/lib/src/engine/pointer_binding.dart b/lib/web_ui/lib/src/engine/pointer_binding.dart index 5bb8e41cc723e..c7ceaa3587816 100644 --- a/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -257,13 +257,13 @@ mixin _WheelEventListenerMixin on _BaseAdapter { _pointerDataConverter.convert( data, change: ui.PointerChange.hover, - timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp), + timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp!), kind: ui.PointerDeviceKind.mouse, signalKind: ui.PointerSignalKind.scroll, device: _mouseDeviceId, physicalX: event.client.x * ui.window.devicePixelRatio as double, physicalY: event.client.y * ui.window.devicePixelRatio as double, - buttons: event.buttons, + buttons: event.buttons!, pressure: 1.0, pressureMin: 0.0, pressureMax: 1.0, @@ -444,23 +444,23 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { @override void setup() { _addPointerEventListener('pointerdown', (html.PointerEvent event) { - final int device = event.pointerId; + final int device = event.pointerId!; final List pointerData = []; final _SanitizedDetails details = _ensureSanitizer(device).sanitizeDownEvent( button: event.button, - buttons: event.buttons, + buttons: event.buttons!, ); _convertEventsToPointerData(data: pointerData, event: event, details: details); _callback(pointerData); }); _addPointerEventListener('pointermove', (html.PointerEvent event) { - final int device = event.pointerId; + final int device = event.pointerId!; final _ButtonSanitizer sanitizer = _ensureSanitizer(device); final List pointerData = []; final Iterable<_SanitizedDetails> detailsList = _expandEvents(event).map( - (html.PointerEvent expandedEvent) => sanitizer.sanitizeMoveEvent(buttons: expandedEvent.buttons), + (html.PointerEvent expandedEvent) => sanitizer.sanitizeMoveEvent(buttons: expandedEvent.buttons!), ); for (_SanitizedDetails details in detailsList) { _convertEventsToPointerData(data: pointerData, event: event, details: details); @@ -469,7 +469,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { }, acceptOutsideGlasspane: true); _addPointerEventListener('pointerup', (html.PointerEvent event) { - final int device = event.pointerId; + final int device = event.pointerId!; final List pointerData = []; final _SanitizedDetails? details = _getSanitizer(device).sanitizeUpEvent(); _removePointerIfUnhoverable(event); @@ -482,7 +482,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { // A browser fires cancel event if it concludes the pointer will no longer // be able to generate events (example: device is deactivated) _addPointerEventListener('pointercancel', (html.PointerEvent event) { - final int device = event.pointerId; + final int device = event.pointerId!; final List pointerData = []; final _SanitizedDetails details = _getSanitizer(device).sanitizeCancelEvent(); _removePointerIfUnhoverable(event); @@ -512,13 +512,13 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { assert(data != null); // ignore: unnecessary_null_comparison assert(event != null); // ignore: unnecessary_null_comparison assert(details != null); // ignore: unnecessary_null_comparison - final ui.PointerDeviceKind kind = _pointerTypeToDeviceKind(event.pointerType); + final ui.PointerDeviceKind kind = _pointerTypeToDeviceKind(event.pointerType!); // We force `device: _mouseDeviceId` on mouse pointers because Wheel events // might come before any PointerEvents, and since wheel events don't contain // pointerId we always assign `device: _mouseDeviceId` to them. - final int device = kind == ui.PointerDeviceKind.mouse ? _mouseDeviceId : event.pointerId; + final int device = kind == ui.PointerDeviceKind.mouse ? _mouseDeviceId : event.pointerId!; final double tilt = _computeHighestTilt(event); - final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp); + final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!); _pointerDataConverter.convert( data, change: details.change, @@ -566,7 +566,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { /// Tilt angle is -90 to + 90. Take maximum deflection and convert to radians. double _computeHighestTilt(html.PointerEvent e) => - (e.tiltX.abs() > e.tiltY.abs() ? e.tiltX : e.tiltY).toDouble() / + (e.tiltX!.abs() > e.tiltY!.abs() ? e.tiltX : e.tiltY)!.toDouble() / 180.0 * math.pi; } @@ -596,12 +596,12 @@ class _TouchAdapter extends _BaseAdapter { @override void setup() { _addTouchEventListener('touchstart', (html.TouchEvent event) { - final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp); + final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!); final List pointerData = []; - for (html.Touch touch in event.changedTouches) { - final nowPressed = _isTouchPressed(touch.identifier); + for (html.Touch touch in event.changedTouches!) { + final nowPressed = _isTouchPressed(touch.identifier!); if (!nowPressed) { - _pressTouch(touch.identifier); + _pressTouch(touch.identifier!); _convertEventToPointerData( data: pointerData, change: ui.PointerChange.down, @@ -616,10 +616,10 @@ class _TouchAdapter extends _BaseAdapter { _addTouchEventListener('touchmove', (html.TouchEvent event) { event.preventDefault(); // Prevents standard overscroll on iOS/Webkit. - final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp); + final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!); final List pointerData = []; - for (html.Touch touch in event.changedTouches) { - final nowPressed = _isTouchPressed(touch.identifier); + for (html.Touch touch in event.changedTouches!) { + final nowPressed = _isTouchPressed(touch.identifier!); if (nowPressed) { _convertEventToPointerData( data: pointerData, @@ -637,12 +637,12 @@ class _TouchAdapter extends _BaseAdapter { // On Safari Mobile, the keyboard does not show unless this line is // added. event.preventDefault(); - final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp); + final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!); final List pointerData = []; - for (html.Touch touch in event.changedTouches) { - final nowPressed = _isTouchPressed(touch.identifier); + for (html.Touch touch in event.changedTouches!) { + final nowPressed = _isTouchPressed(touch.identifier!); if (nowPressed) { - _unpressTouch(touch.identifier); + _unpressTouch(touch.identifier!); _convertEventToPointerData( data: pointerData, change: ui.PointerChange.up, @@ -656,12 +656,12 @@ class _TouchAdapter extends _BaseAdapter { }); _addTouchEventListener('touchcancel', (html.TouchEvent event) { - final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp); + final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!); final List pointerData = []; - for (html.Touch touch in event.changedTouches) { - final nowPressed = _isTouchPressed(touch.identifier); + for (html.Touch touch in event.changedTouches!) { + final nowPressed = _isTouchPressed(touch.identifier!); if (nowPressed) { - _unpressTouch(touch.identifier); + _unpressTouch(touch.identifier!); _convertEventToPointerData( data: pointerData, change: ui.PointerChange.cancel, @@ -688,7 +688,7 @@ class _TouchAdapter extends _BaseAdapter { timeStamp: timeStamp, kind: ui.PointerDeviceKind.touch, signalKind: ui.PointerSignalKind.none, - device: touch.identifier, + device: touch.identifier!, physicalX: touch.client.x * ui.window.devicePixelRatio as double, physicalY: touch.client.y * ui.window.devicePixelRatio as double, buttons: pressed ? _kPrimaryMouseButton : 0, @@ -746,7 +746,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin { final _SanitizedDetails sanitizedDetails = _sanitizer.sanitizeDownEvent( button: event.button, - buttons: event.buttons, + buttons: event.buttons!, ); _convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails); _callback(pointerData); @@ -754,7 +754,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin { _addMouseEventListener('mousemove', (html.MouseEvent event) { final List pointerData = []; - final _SanitizedDetails sanitizedDetails = _sanitizer.sanitizeMoveEvent(buttons: event.buttons); + final _SanitizedDetails sanitizedDetails = _sanitizer.sanitizeMoveEvent(buttons: event.buttons!); _convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails); _callback(pointerData); }, acceptOutsideGlasspane: true); @@ -764,7 +764,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin { final bool isEndOfDrag = event.buttons == 0; final _SanitizedDetails sanitizedDetails = isEndOfDrag ? _sanitizer.sanitizeUpEvent()! : - _sanitizer.sanitizeMoveEvent(buttons: event.buttons); + _sanitizer.sanitizeMoveEvent(buttons: event.buttons!); _convertEventsToPointerData(data: pointerData, event: event, details: sanitizedDetails); _callback(pointerData); }, acceptOutsideGlasspane: true); @@ -794,7 +794,7 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin { _pointerDataConverter.convert( data, change: details.change, - timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp), + timeStamp: _BaseAdapter._eventTimeStampToDuration(event.timeStamp!), kind: ui.PointerDeviceKind.mouse, signalKind: ui.PointerSignalKind.none, device: _mouseDeviceId, diff --git a/lib/web_ui/lib/src/engine/semantics/incrementable.dart b/lib/web_ui/lib/src/engine/semantics/incrementable.dart index 3a86c33494c35..35bc7b43da61e 100644 --- a/lib/web_ui/lib/src/engine/semantics/incrementable.dart +++ b/lib/web_ui/lib/src/engine/semantics/incrementable.dart @@ -45,11 +45,11 @@ class Incrementable extends RoleManager { _element.setAttribute('role', 'slider'); _element.addEventListener('change', (_) { - if (_element.disabled) { + if (_element.disabled!) { return; } _pendingResync = true; - final int newInputValue = int.parse(_element.value); + final int newInputValue = int.parse(_element.value!); if (newInputValue > _currentSurrogateValue) { _currentSurrogateValue += 1; window.invokeOnSemanticsAction( @@ -84,7 +84,7 @@ class Incrementable extends RoleManager { void _enableBrowserGestureHandling() { assert(semanticsObject.owner.gestureMode == GestureMode.browserGestures); - if (!_element.disabled) { + if (!_element.disabled!) { return; } _element.disabled = false; @@ -123,7 +123,7 @@ class Incrementable extends RoleManager { } void _disableBrowserGestureHandling() { - if (_element.disabled) { + if (_element.disabled!) { return; } _element.disabled = true; diff --git a/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart b/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart index b9eff3e892ce6..86c3e4115d4d7 100644 --- a/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart +++ b/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart @@ -331,7 +331,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler { case 'touchstart': case 'touchend': final html.TouchEvent touch = event as html.TouchEvent; - activationPoint = touch.changedTouches.first.client; + activationPoint = touch.changedTouches!.first.client; break; default: // The event is not relevant, forward to framework as normal. diff --git a/lib/web_ui/lib/src/engine/semantics/text_field.dart b/lib/web_ui/lib/src/engine/semantics/text_field.dart index bc5bf16116e5a..2e80987b0b739 100644 --- a/lib/web_ui/lib/src/engine/semantics/text_field.dart +++ b/lib/web_ui/lib/src/engine/semantics/text_field.dart @@ -165,8 +165,8 @@ class TextField extends RoleManager { _textFieldElement.addEventListener('touchstart', (html.Event event) { textEditing.useCustomEditableElement(textEditingElement); final html.TouchEvent touchEvent = event as html.TouchEvent; - lastTouchStartOffsetX = touchEvent.changedTouches.last.client.x; - lastTouchStartOffsetY = touchEvent.changedTouches.last.client.y; + lastTouchStartOffsetX = touchEvent.changedTouches!.last.client.x; + lastTouchStartOffsetY = touchEvent.changedTouches!.last.client.y; }, true); _textFieldElement.addEventListener('touchend', (html.Event event) { @@ -174,8 +174,8 @@ class TextField extends RoleManager { if (lastTouchStartOffsetX != null) { assert(lastTouchStartOffsetY != null); - final num offsetX = touchEvent.changedTouches.last.client.x; - final num offsetY = touchEvent.changedTouches.last.client.y; + final num offsetX = touchEvent.changedTouches!.last.client.x; + final num offsetY = touchEvent.changedTouches!.last.client.y; // This should match the similar constant define in: // diff --git a/lib/web_ui/lib/src/engine/surface/scene.dart b/lib/web_ui/lib/src/engine/surface/scene.dart index f1c6afcbb98ef..7efd71550281b 100644 --- a/lib/web_ui/lib/src/engine/surface/scene.dart +++ b/lib/web_ui/lib/src/engine/surface/scene.dart @@ -38,8 +38,8 @@ class PersistedScene extends PersistedContainerSurface { // TODO(yjbanov): in the add2app scenario where we might be hosted inside // a custom element, this will be different. We will need to // update this code when we add add2app support. - final double screenWidth = html.window.innerWidth.toDouble(); - final double screenHeight = html.window.innerHeight.toDouble(); + final double screenWidth = html.window.innerWidth!.toDouble(); + final double screenHeight = html.window.innerHeight!.toDouble(); _localClipBounds = ui.Rect.fromLTRB(0, 0, screenWidth, screenHeight); _localTransformInverse = Matrix4.identity(); _projectedClip = null; diff --git a/lib/web_ui/lib/src/engine/surface/surface_stats.dart b/lib/web_ui/lib/src/engine/surface/surface_stats.dart index cb539752195d8..5cbadd6c16080 100644 --- a/lib/web_ui/lib/src/engine/surface/surface_stats.dart +++ b/lib/web_ui/lib/src/engine/surface/surface_stats.dart @@ -90,7 +90,7 @@ class _DebugSurfaceStats { html.CanvasRenderingContext2D? _debugSurfaceStatsOverlayCtx; void _debugRepaintSurfaceStatsOverlay(PersistedScene scene) { - final int overlayWidth = html.window.innerWidth; + final int overlayWidth = html.window.innerWidth!; const int rowHeight = 30; const int rowCount = 4; const int overlayHeight = rowHeight * rowCount; @@ -124,9 +124,9 @@ void _debugRepaintSurfaceStatsOverlay(PersistedScene scene) { ..fill(); final double physicalScreenWidth = - html.window.innerWidth * EngineWindow.browserDevicePixelRatio; + html.window.innerWidth! * EngineWindow.browserDevicePixelRatio; final double physicalScreenHeight = - html.window.innerHeight * EngineWindow.browserDevicePixelRatio; + html.window.innerHeight! * EngineWindow.browserDevicePixelRatio; final double physicsScreenPixelCount = physicalScreenWidth * physicalScreenHeight; @@ -295,9 +295,9 @@ void _debugPrintSurfaceStats(PersistedScene scene, int frameNumber) { return pixels; }).fold(0, (int total, int pixels) => total + pixels); final double physicalScreenWidth = - html.window.innerWidth * EngineWindow.browserDevicePixelRatio; + html.window.innerWidth! * EngineWindow.browserDevicePixelRatio; final double physicalScreenHeight = - html.window.innerHeight * EngineWindow.browserDevicePixelRatio; + html.window.innerHeight! * EngineWindow.browserDevicePixelRatio; final double physicsScreenPixelCount = physicalScreenWidth * physicalScreenHeight; final double screenPixelRatio = pixelCount / physicsScreenPixelCount; diff --git a/lib/web_ui/lib/src/engine/text/font_collection.dart b/lib/web_ui/lib/src/engine/text/font_collection.dart index 91b1909964f4c..56444135d3e40 100644 --- a/lib/web_ui/lib/src/engine/text/font_collection.dart +++ b/lib/web_ui/lib/src/engine/text/font_collection.dart @@ -94,7 +94,7 @@ class FontCollection { _assetFontManager = null; _testFontManager = null; if (supportsFontsClearApi) { - html.document.fonts.clear(); + html.document.fonts!.clear(); } } } @@ -178,7 +178,7 @@ class FontManager { try { final html.FontFace fontFace = html.FontFace(family, asset, descriptors); _fontLoadingFutures.add(fontFace.load().then((_) { - html.document.fonts.add(fontFace); + html.document.fonts!.add(fontFace); }, onError: (dynamic e) { html.window.console .warn('Error while trying to load font family "$family":\n$e'); @@ -195,7 +195,7 @@ class FontManager { // through the returned future. final html.FontFace fontFace = html.FontFace(family, list); return fontFace.load().then((_) { - html.document.fonts.add(fontFace); + html.document.fonts!.add(fontFace); // There might be paragraph measurements for this new font before it is // loaded. They were measured using fallback font, so we should clear the // cache. @@ -309,4 +309,4 @@ class _PolyfillFontManager extends FontManager { } final bool supportsFontLoadingApi = js_util.hasProperty(html.window, 'FontFace'); -final bool supportsFontsClearApi = js_util.hasProperty(html.document, 'fonts') && js_util.hasProperty(html.document.fonts, 'clear'); +final bool supportsFontsClearApi = js_util.hasProperty(html.document, 'fonts') && js_util.hasProperty(html.document.fonts!, 'clear'); diff --git a/lib/web_ui/lib/src/engine/text/measurement.dart b/lib/web_ui/lib/src/engine/text/measurement.dart index 7d844f913418a..d123bff61c7c1 100644 --- a/lib/web_ui/lib/src/engine/text/measurement.dart +++ b/lib/web_ui/lib/src/engine/text/measurement.dart @@ -690,7 +690,7 @@ double _measureSubstring( final String sub = start == 0 && end == text.length ? text : text.substring(start, end); final double width = - _canvasContext.measureText(sub).width + letterSpacing * sub.length as double; + _canvasContext.measureText(sub).width! + letterSpacing * sub.length as double; // What we are doing here is we are rounding to the nearest 2nd decimal // point. So 39.999423 becomes 40, and 11.243982 becomes 11.24. diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index 67469c59a68c6..dd7395ac1f842 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -73,11 +73,11 @@ class EngineWindow extends ui.Window { double windowInnerHeight; final html.VisualViewport? viewport = html.window.visualViewport; if (viewport != null) { - windowInnerWidth = viewport.width * devicePixelRatio as double; - windowInnerHeight = viewport.height * devicePixelRatio as double; + windowInnerWidth = viewport.width! * devicePixelRatio as double; + windowInnerHeight = viewport.height! * devicePixelRatio as double; } else { - windowInnerWidth = html.window.innerWidth * devicePixelRatio; - windowInnerHeight = html.window.innerHeight * devicePixelRatio; + windowInnerWidth = html.window.innerWidth! * devicePixelRatio; + windowInnerHeight = html.window.innerHeight! * devicePixelRatio; } _physicalSize = ui.Size( windowInnerWidth, @@ -90,9 +90,9 @@ class EngineWindow extends ui.Window { double windowInnerHeight; final html.VisualViewport? viewport = html.window.visualViewport; if (viewport != null) { - windowInnerHeight = viewport.height * devicePixelRatio as double; + windowInnerHeight = viewport.height! * devicePixelRatio as double; } else { - windowInnerHeight = html.window.innerHeight * devicePixelRatio; + windowInnerHeight = html.window.innerHeight! * devicePixelRatio; } final double bottomPadding = _physicalSize!.height - windowInnerHeight; _viewInsets = @@ -117,11 +117,11 @@ class EngineWindow extends ui.Window { double height = 0; double width = 0; if (html.window.visualViewport != null) { - height = html.window.visualViewport!.height * devicePixelRatio as double; - width = html.window.visualViewport!.width * devicePixelRatio as double; + height = html.window.visualViewport!.height! * devicePixelRatio as double; + width = html.window.visualViewport!.width! * devicePixelRatio as double; } else { - height = html.window.innerHeight * devicePixelRatio; - width = html.window.innerWidth * devicePixelRatio; + height = html.window.innerHeight! * devicePixelRatio; + width = html.window.innerWidth! * devicePixelRatio; } // First confirm both heught and width is effected. if (_physicalSize!.height != height && _physicalSize!.width != width) { @@ -280,15 +280,15 @@ class EngineWindow extends ui.Window { static List parseBrowserLanguages() { // TODO(yjbanov): find a solution for IE - final bool languagesFeatureMissing = !js_util.hasProperty(html.window.navigator, 'languages'); - if (languagesFeatureMissing || html.window.navigator.languages.isEmpty) { + var languages = html.window.navigator.languages; + if (languages == null || languages.isEmpty) { // To make it easier for the app code, let's not leave the locales list // empty. This way there's fewer corner cases for apps to handle. return const [_defaultLocale]; } final List locales = []; - for (final String language in html.window.navigator.languages) { + for (final String language in languages) { final List parts = language.split('-'); if (parts.length > 1) { locales.add(ui.Locale(parts.first, parts.last)); @@ -703,7 +703,7 @@ class EngineWindow extends ui.Window { _brightnessMediaQueryListener = (html.Event event) { final html.MediaQueryListEvent mqEvent = event as html.MediaQueryListEvent; _updatePlatformBrightness( - mqEvent.matches ? ui.Brightness.dark : ui.Brightness.light); + mqEvent.matches! ? ui.Brightness.dark : ui.Brightness.light); }; _brightnessMediaQuery.addListener(_brightnessMediaQueryListener); registerHotRestartListener(() {