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

Commit af5717e

Browse files
authored
[web] Fix setPreferredOrientations failure on iOS due to NNBD change. (#21531)
1 parent f37a0b1 commit af5717e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,18 @@ flt-glass-pane * {
536536
Future<bool> setPreferredOrientation(List<dynamic>? orientations) {
537537
final html.Screen screen = html.window.screen!;
538538
if (!_unsafeIsNull(screen)) {
539-
final html.ScreenOrientation screenOrientation =
540-
screen.orientation!;
539+
final html.ScreenOrientation? screenOrientation =
540+
screen.orientation;
541541
if (!_unsafeIsNull(screenOrientation)) {
542542
if (orientations!.isEmpty) {
543-
screenOrientation.unlock();
543+
screenOrientation!.unlock();
544544
return Future.value(true);
545545
} else {
546546
String? lockType = _deviceOrientationToLockType(orientations.first);
547547
if (lockType != null) {
548548
final Completer<bool> completer = Completer<bool>();
549549
try {
550-
screenOrientation.lock(lockType).then((dynamic _) {
550+
screenOrientation!.lock(lockType).then((dynamic _) {
551551
completer.complete(true);
552552
}).catchError((dynamic error) {
553553
// On Chrome desktop an error with 'not supported on this device

lib/web_ui/test/engine/window_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// @dart = 2.6
66
import 'dart:async';
7+
import 'dart:js_util' as js_util;
78
import 'dart:html' as html;
89
import 'dart:typed_data';
910

@@ -247,6 +248,29 @@ void testMain() {
247248
expect(responded, isTrue);
248249
});
249250

251+
/// Regression test for https://github.com/flutter/flutter/issues/66128.
252+
test('setPreferredOrientation responds even if browser doesn\'t support api', () async {
253+
final html.Screen screen = html.window.screen;
254+
js_util.setProperty(screen, 'orientation', null);
255+
bool responded = false;
256+
257+
final Completer<void> completer = Completer<void>();
258+
final ByteData inputData = JSONMethodCodec().encodeMethodCall(MethodCall(
259+
'SystemChrome.setPreferredOrientations',
260+
<dynamic>[]));
261+
262+
window.sendPlatformMessage(
263+
'flutter/platform',
264+
inputData,
265+
(outputData) {
266+
responded = true;
267+
completer.complete();
268+
},
269+
);
270+
await completer.future;
271+
expect(responded, true);
272+
});
273+
250274
test('Window implements locale, locales, and locale change notifications', () async {
251275
// This will count how many times we notified about locale changes.
252276
int localeChangedCount = 0;

0 commit comments

Comments
 (0)