diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart index 683da328ed..c7b4e36b12 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart @@ -727,12 +727,12 @@ $_glassPaneTagName * { /// defer to the operating system default. /// /// See w3c screen api: https://www.w3.org/TR/screen-orientation/ - Future setPreferredOrientation(List? orientations) { + Future setPreferredOrientation(List 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; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 0de8f8d73a..e1e9971541 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -396,9 +396,12 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { callback, codec.encodeSuccessEnvelope(true)); return; case 'SystemChrome.setApplicationSwitcherDescription': - final Map arguments = decoded.arguments; - domRenderer.setTitle(arguments['label']); - domRenderer.setThemeColor(ui.Color(arguments['primaryColor'])); + final Map 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; diff --git a/engine/src/flutter/lib/web_ui/test/engine/window_test.dart b/engine/src/flutter/lib/web_ui/test/engine/window_test.dart index 9da1a08f19..fe02d05d88 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/window_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/window_test.dart @@ -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 completer = Completer(); + final Completer completer = Completer(); final ByteData inputData = JSONMethodCodec().encodeMethodCall(MethodCall( 'SystemChrome.setPreferredOrientations', [])); @@ -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 { diff --git a/engine/src/flutter/lib/web_ui/test/title_test.dart b/engine/src/flutter/lib/web_ui/test/title_test.dart index 17a2489821..a1839eadb7 100644 --- a/engine/src/flutter/lib/web_ui/test/title_test.dart +++ b/engine/src/flutter/lib/web_ui/test/title_test.dart @@ -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', + { + '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', + { + })), + null); + + expect(document.title, ''); + }); }); }