[web] Fix setPreferredOrientations failure on iOS due to NNBD change. (flutter/engine#21531)
This commit is contained in:
@@ -536,18 +536,18 @@ flt-glass-pane * {
|
||||
Future<bool> setPreferredOrientation(List<dynamic>? 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<bool> completer = Completer<bool>();
|
||||
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
|
||||
|
||||
@@ -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<void> completer = Completer<void>();
|
||||
final ByteData inputData = JSONMethodCodec().encodeMethodCall(MethodCall(
|
||||
'SystemChrome.setPreferredOrientations',
|
||||
<dynamic>[]));
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user