Update SystemUIOverlayStyle to support null contrast enforcement (#91396)
This commit is contained in:
@@ -300,9 +300,11 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
|
||||
statusBarBrightness: upperOverlayStyle?.statusBarBrightness,
|
||||
statusBarIconBrightness: upperOverlayStyle?.statusBarIconBrightness,
|
||||
statusBarColor: upperOverlayStyle?.statusBarColor,
|
||||
systemStatusBarContrastEnforced: upperOverlayStyle?.systemStatusBarContrastEnforced,
|
||||
systemNavigationBarColor: lowerOverlayStyle?.systemNavigationBarColor,
|
||||
systemNavigationBarDividerColor: lowerOverlayStyle?.systemNavigationBarDividerColor,
|
||||
systemNavigationBarIconBrightness: lowerOverlayStyle?.systemNavigationBarIconBrightness,
|
||||
systemNavigationBarContrastEnforced: lowerOverlayStyle?.systemNavigationBarContrastEnforced,
|
||||
);
|
||||
SystemChrome.setSystemUIOverlayStyle(overlayStyle);
|
||||
}
|
||||
|
||||
@@ -289,12 +289,12 @@ class SystemUiOverlayStyle {
|
||||
return <String, dynamic>{
|
||||
'systemNavigationBarColor': systemNavigationBarColor?.value,
|
||||
'systemNavigationBarDividerColor': systemNavigationBarDividerColor?.value,
|
||||
'systemStatusBarContrastEnforced' : systemStatusBarContrastEnforced ?? true,
|
||||
'systemStatusBarContrastEnforced': systemStatusBarContrastEnforced,
|
||||
'statusBarColor': statusBarColor?.value,
|
||||
'statusBarBrightness': statusBarBrightness?.toString(),
|
||||
'statusBarIconBrightness': statusBarIconBrightness?.toString(),
|
||||
'systemNavigationBarIconBrightness': systemNavigationBarIconBrightness?.toString(),
|
||||
'systemNavigationBarContrastEnforced' : systemNavigationBarContrastEnforced ?? true,
|
||||
'systemNavigationBarContrastEnforced': systemNavigationBarContrastEnforced,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,60 @@ void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
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
|
||||
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
|
||||
expect(tester.binding.microtaskCount, equals(1));
|
||||
|
||||
// Flush all microtasks
|
||||
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(log.isEmpty, isTrue);
|
||||
|
||||
// The second call with the same value should be a no-op
|
||||
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
|
||||
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 {
|
||||
@@ -157,12 +200,12 @@ void main() {
|
||||
expect(systemUiOverlayStyle.toString(), 'SystemUiOverlayStyle({'
|
||||
'systemNavigationBarColor: null, '
|
||||
'systemNavigationBarDividerColor: null, '
|
||||
'systemStatusBarContrastEnforced: true, '
|
||||
'systemStatusBarContrastEnforced: null, '
|
||||
'statusBarColor: null, '
|
||||
'statusBarBrightness: null, '
|
||||
'statusBarIconBrightness: null, '
|
||||
'systemNavigationBarIconBrightness: null, '
|
||||
'systemNavigationBarContrastEnforced: true})',
|
||||
'systemNavigationBarContrastEnforced: null})',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user