From af5717eb1087242d170cb235385633bb94fe87c4 Mon Sep 17 00:00:00 2001 From: Ferhat Date: Thu, 1 Oct 2020 14:00:01 -0700 Subject: [PATCH] [web] Fix setPreferredOrientations failure on iOS due to NNBD change. (#21531) --- lib/web_ui/lib/src/engine/dom_renderer.dart | 8 +++---- lib/web_ui/test/engine/window_test.dart | 24 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/web_ui/lib/src/engine/dom_renderer.dart b/lib/web_ui/lib/src/engine/dom_renderer.dart index a4cb42149..9e1a3b50f 100644 --- a/lib/web_ui/lib/src/engine/dom_renderer.dart +++ b/lib/web_ui/lib/src/engine/dom_renderer.dart @@ -536,18 +536,18 @@ flt-glass-pane * { Future setPreferredOrientation(List? orientations) { final html.Screen screen = html.window.screen!; if (!_unsafeIsNull(screen)) { - final html.ScreenOrientation screenOrientation = - screen.orientation!; + final html.ScreenOrientation? screenOrientation = + screen.orientation; if (!_unsafeIsNull(screenOrientation)) { if (orientations!.isEmpty) { - screenOrientation.unlock(); + screenOrientation!.unlock(); return Future.value(true); } else { String? lockType = _deviceOrientationToLockType(orientations.first); if (lockType != null) { final Completer completer = Completer(); try { - screenOrientation.lock(lockType).then((dynamic _) { + screenOrientation!.lock(lockType).then((dynamic _) { completer.complete(true); }).catchError((dynamic error) { // On Chrome desktop an error with 'not supported on this device diff --git a/lib/web_ui/test/engine/window_test.dart b/lib/web_ui/test/engine/window_test.dart index 6c212f124..15e381440 100644 --- a/lib/web_ui/test/engine/window_test.dart +++ b/lib/web_ui/test/engine/window_test.dart @@ -4,6 +4,7 @@ // @dart = 2.6 import 'dart:async'; +import 'dart:js_util' as js_util; import 'dart:html' as html; import 'dart:typed_data'; @@ -247,6 +248,29 @@ void testMain() { expect(responded, isTrue); }); + /// Regression test for https://github.com/flutter/flutter/issues/66128. + test('setPreferredOrientation responds even if browser doesn\'t support api', () async { + final html.Screen screen = html.window.screen; + js_util.setProperty(screen, 'orientation', null); + bool responded = false; + + final Completer completer = Completer(); + final ByteData inputData = JSONMethodCodec().encodeMethodCall(MethodCall( + 'SystemChrome.setPreferredOrientations', + [])); + + window.sendPlatformMessage( + 'flutter/platform', + inputData, + (outputData) { + responded = true; + completer.complete(); + }, + ); + await completer.future; + expect(responded, true); + }); + test('Window implements locale, locales, and locale change notifications', () async { // This will count how many times we notified about locale changes. int localeChangedCount = 0; -- GitLab