Unverified Commit 0a3ae081 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Update SystemUIOverlayStyle to support null contrast enforcement (#91396)

parent 71a59b48
...@@ -300,9 +300,11 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> ...@@ -300,9 +300,11 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
statusBarBrightness: upperOverlayStyle?.statusBarBrightness, statusBarBrightness: upperOverlayStyle?.statusBarBrightness,
statusBarIconBrightness: upperOverlayStyle?.statusBarIconBrightness, statusBarIconBrightness: upperOverlayStyle?.statusBarIconBrightness,
statusBarColor: upperOverlayStyle?.statusBarColor, statusBarColor: upperOverlayStyle?.statusBarColor,
systemStatusBarContrastEnforced: upperOverlayStyle?.systemStatusBarContrastEnforced,
systemNavigationBarColor: lowerOverlayStyle?.systemNavigationBarColor, systemNavigationBarColor: lowerOverlayStyle?.systemNavigationBarColor,
systemNavigationBarDividerColor: lowerOverlayStyle?.systemNavigationBarDividerColor, systemNavigationBarDividerColor: lowerOverlayStyle?.systemNavigationBarDividerColor,
systemNavigationBarIconBrightness: lowerOverlayStyle?.systemNavigationBarIconBrightness, systemNavigationBarIconBrightness: lowerOverlayStyle?.systemNavigationBarIconBrightness,
systemNavigationBarContrastEnforced: lowerOverlayStyle?.systemNavigationBarContrastEnforced,
); );
SystemChrome.setSystemUIOverlayStyle(overlayStyle); SystemChrome.setSystemUIOverlayStyle(overlayStyle);
} }
......
...@@ -289,12 +289,12 @@ class SystemUiOverlayStyle { ...@@ -289,12 +289,12 @@ class SystemUiOverlayStyle {
return <String, dynamic>{ return <String, dynamic>{
'systemNavigationBarColor': systemNavigationBarColor?.value, 'systemNavigationBarColor': systemNavigationBarColor?.value,
'systemNavigationBarDividerColor': systemNavigationBarDividerColor?.value, 'systemNavigationBarDividerColor': systemNavigationBarDividerColor?.value,
'systemStatusBarContrastEnforced' : systemStatusBarContrastEnforced ?? true, 'systemStatusBarContrastEnforced': systemStatusBarContrastEnforced,
'statusBarColor': statusBarColor?.value, 'statusBarColor': statusBarColor?.value,
'statusBarBrightness': statusBarBrightness?.toString(), 'statusBarBrightness': statusBarBrightness?.toString(),
'statusBarIconBrightness': statusBarIconBrightness?.toString(), 'statusBarIconBrightness': statusBarIconBrightness?.toString(),
'systemNavigationBarIconBrightness': systemNavigationBarIconBrightness?.toString(), 'systemNavigationBarIconBrightness': systemNavigationBarIconBrightness?.toString(),
'systemNavigationBarContrastEnforced' : systemNavigationBarContrastEnforced ?? true, 'systemNavigationBarContrastEnforced': systemNavigationBarContrastEnforced,
}; };
} }
......
...@@ -10,17 +10,60 @@ void main() { ...@@ -10,17 +10,60 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
testWidgets('SystemChrome overlay style test', (WidgetTester tester) async { testWidgets('SystemChrome overlay style test', (WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
log.add(methodCall);
});
// The first call is a cache miss and will queue a microtask // The first call is a cache miss and will queue a microtask
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
expect(tester.binding.microtaskCount, equals(1)); expect(tester.binding.microtaskCount, equals(1));
// Flush all microtasks // Flush all microtasks
await tester.idle(); await tester.idle();
expect(log, hasLength(1));
expect(log.single, isMethodCall(
'SystemChrome.setSystemUIOverlayStyle',
arguments: <String, dynamic>{
'systemNavigationBarColor': 4278190080,
'systemNavigationBarDividerColor': null,
'systemStatusBarContrastEnforced': null,
'statusBarColor': null,
'statusBarBrightness': 'Brightness.dark',
'statusBarIconBrightness': 'Brightness.light',
'systemNavigationBarIconBrightness': 'Brightness.light',
'systemNavigationBarContrastEnforced': null
},
));
log.clear();
expect(tester.binding.microtaskCount, equals(0)); expect(tester.binding.microtaskCount, equals(0));
expect(log.isEmpty, isTrue);
// The second call with the same value should be a no-op // The second call with the same value should be a no-op
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
expect(tester.binding.microtaskCount, equals(0)); expect(tester.binding.microtaskCount, equals(0));
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
systemStatusBarContrastEnforced: false,
systemNavigationBarContrastEnforced: true
));
expect(tester.binding.microtaskCount, equals(1));
await tester.idle();
expect(log, hasLength(1));
expect(log.single, isMethodCall(
'SystemChrome.setSystemUIOverlayStyle',
arguments: <String, dynamic>{
'systemNavigationBarColor': null,
'systemNavigationBarDividerColor': null,
'systemStatusBarContrastEnforced': false,
'statusBarColor': null,
'statusBarBrightness': null,
'statusBarIconBrightness': null,
'systemNavigationBarIconBrightness': null,
'systemNavigationBarContrastEnforced': true
},
));
}); });
test('setPreferredOrientations control test', () async { test('setPreferredOrientations control test', () async {
...@@ -157,12 +200,12 @@ void main() { ...@@ -157,12 +200,12 @@ void main() {
expect(systemUiOverlayStyle.toString(), 'SystemUiOverlayStyle({' expect(systemUiOverlayStyle.toString(), 'SystemUiOverlayStyle({'
'systemNavigationBarColor: null, ' 'systemNavigationBarColor: null, '
'systemNavigationBarDividerColor: null, ' 'systemNavigationBarDividerColor: null, '
'systemStatusBarContrastEnforced: true, ' 'systemStatusBarContrastEnforced: null, '
'statusBarColor: null, ' 'statusBarColor: null, '
'statusBarBrightness: null, ' 'statusBarBrightness: null, '
'statusBarIconBrightness: null, ' 'statusBarIconBrightness: null, '
'systemNavigationBarIconBrightness: null, ' 'systemNavigationBarIconBrightness: null, '
'systemNavigationBarContrastEnforced: true})', 'systemNavigationBarContrastEnforced: null})',
); );
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment