[web] Allow some more nulls in platform_dispatcher. (flutter/engine#26626)
This commit is contained in:
@@ -727,12 +727,12 @@ $_glassPaneTagName * {
|
||||
/// defer to the operating system default.
|
||||
///
|
||||
/// See w3c screen api: https://www.w3.org/TR/screen-orientation/
|
||||
Future<bool> setPreferredOrientation(List<dynamic>? orientations) {
|
||||
Future<bool> setPreferredOrientation(List<dynamic> orientations) {
|
||||
final html.Screen screen = html.window.screen!;
|
||||
if (!_unsafeIsNull(screen)) {
|
||||
final html.ScreenOrientation? screenOrientation = screen.orientation;
|
||||
if (!_unsafeIsNull(screenOrientation)) {
|
||||
if (orientations!.isEmpty) {
|
||||
if (orientations.isEmpty) {
|
||||
screenOrientation!.unlock();
|
||||
return Future.value(true);
|
||||
} else {
|
||||
@@ -760,7 +760,7 @@ $_glassPaneTagName * {
|
||||
}
|
||||
|
||||
// Converts device orientation to w3c OrientationLockType enum.
|
||||
static String? _deviceOrientationToLockType(String deviceOrientation) {
|
||||
static String? _deviceOrientationToLockType(String? deviceOrientation) {
|
||||
switch (deviceOrientation) {
|
||||
case 'DeviceOrientation.portraitUp':
|
||||
return orientationLockTypePortraitPrimary;
|
||||
|
||||
@@ -396,9 +396,12 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
||||
callback, codec.encodeSuccessEnvelope(true));
|
||||
return;
|
||||
case 'SystemChrome.setApplicationSwitcherDescription':
|
||||
final Map<String, dynamic> arguments = decoded.arguments;
|
||||
domRenderer.setTitle(arguments['label']);
|
||||
domRenderer.setThemeColor(ui.Color(arguments['primaryColor']));
|
||||
final Map<String, Object> arguments = decoded.arguments;
|
||||
// TODO: Find more appropriate defaults? Or noop when values are null?
|
||||
final String label = arguments['label'] as String? ?? '';
|
||||
final int primaryColor = arguments['primaryColor'] as int? ?? 0xFF000000;
|
||||
domRenderer.setTitle(label);
|
||||
domRenderer.setThemeColor(ui.Color(primaryColor));
|
||||
_replyToPlatformMessage(
|
||||
callback, codec.encodeSuccessEnvelope(true));
|
||||
return;
|
||||
|
||||
@@ -301,9 +301,8 @@ void testMain() {
|
||||
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 Completer<bool> completer = Completer<bool>();
|
||||
final ByteData inputData = JSONMethodCodec().encodeMethodCall(MethodCall(
|
||||
'SystemChrome.setPreferredOrientations',
|
||||
<dynamic>[]));
|
||||
@@ -312,12 +311,11 @@ void testMain() {
|
||||
'flutter/platform',
|
||||
inputData,
|
||||
(outputData) {
|
||||
responded = true;
|
||||
completer.complete();
|
||||
completer.complete(true);
|
||||
},
|
||||
);
|
||||
await completer.future;
|
||||
expect(responded, isTrue);
|
||||
|
||||
expect(await completer.future, isTrue);
|
||||
});
|
||||
|
||||
test('SingletonFlutterWindow implements locale, locales, and locale change notifications', () async {
|
||||
|
||||
@@ -49,5 +49,39 @@ void testMain() {
|
||||
|
||||
expect(document.title, 'Different title');
|
||||
});
|
||||
|
||||
test('supports null title and primaryColor', () {
|
||||
// Run the unit test without emulating Flutter tester environment.
|
||||
ui.debugEmulateFlutterTesterEnvironment = false;
|
||||
|
||||
// TODO(yjbanov): https://github.com/flutter/flutter/issues/39159
|
||||
document.title = 'Something Else';
|
||||
expect(document.title, 'Something Else');
|
||||
|
||||
ui.window.sendPlatformMessage(
|
||||
'flutter/platform',
|
||||
codec.encodeMethodCall(const MethodCall(
|
||||
'SystemChrome.setApplicationSwitcherDescription',
|
||||
<String, dynamic>{
|
||||
'label': null,
|
||||
'primaryColor': null,
|
||||
})),
|
||||
null);
|
||||
|
||||
expect(document.title, '');
|
||||
|
||||
document.title = 'Something Else';
|
||||
expect(document.title, 'Something Else');
|
||||
|
||||
ui.window.sendPlatformMessage(
|
||||
'flutter/platform',
|
||||
codec.encodeMethodCall(const MethodCall(
|
||||
'SystemChrome.setApplicationSwitcherDescription',
|
||||
<String, dynamic>{
|
||||
})),
|
||||
null);
|
||||
|
||||
expect(document.title, '');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user