未验证 提交 af5717eb 编写于 作者: F Ferhat 提交者: GitHub

[web] Fix setPreferredOrientations failure on iOS due to NNBD change. (#21531)

上级 f37a0b12
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册