Ensure dark theme is used when high contrast dark theme isn't provided (#62668)

This commit is contained in:
Rami 2020-08-04 11:32:36 -04:00 committed by GitHub
parent c90c4b35ac
commit 643da4b7a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -655,11 +655,11 @@ class _MaterialAppState extends State<MaterialApp> {
final bool highContrast = MediaQuery.highContrastOf(context); final bool highContrast = MediaQuery.highContrastOf(context);
ThemeData theme; ThemeData theme;
if (useDarkTheme && highContrast) { if (useDarkTheme && highContrast && widget.highContrastDarkTheme != null) {
theme = widget.highContrastDarkTheme; theme = widget.highContrastDarkTheme;
} else if (useDarkTheme) { } else if (useDarkTheme && widget.darkTheme != null) {
theme = widget.darkTheme; theme = widget.darkTheme;
} else if (highContrast) { } else if (highContrast && widget.highContrastTheme != null) {
theme = widget.highContrastTheme; theme = widget.highContrastTheme;
} }
theme ??= widget.theme ?? ThemeData.light(); theme ??= widget.theme ?? ThemeData.light();

View File

@ -812,6 +812,34 @@ void main() {
tester.binding.window.accessibilityFeaturesTestValue = null; tester.binding.window.accessibilityFeaturesTestValue = null;
}); });
testWidgets('MaterialApp uses dark theme when no high contrast dark theme is provided', (WidgetTester tester) async {
tester.binding.window.platformBrightnessTestValue = Brightness.dark;
tester.binding.window.accessibilityFeaturesTestValue = MockAccessibilityFeature();
ThemeData appliedTheme;
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
primaryColor: Colors.lightBlue,
),
darkTheme: ThemeData(
primaryColor: Colors.lightGreen,
),
home: Builder(
builder: (BuildContext context) {
appliedTheme = Theme.of(context);
return const SizedBox();
},
),
),
);
expect(appliedTheme.primaryColor, Colors.lightGreen);
tester.binding.window.accessibilityFeaturesTestValue = null;
tester.binding.window.platformBrightnessTestValue = null;
});
testWidgets('MaterialApp switches themes when the Window platformBrightness changes.', (WidgetTester tester) async { testWidgets('MaterialApp switches themes when the Window platformBrightness changes.', (WidgetTester tester) async {
// Mock the Window to explicitly report a light platformBrightness. // Mock the Window to explicitly report a light platformBrightness.
final TestWidgetsFlutterBinding binding = tester.binding; final TestWidgetsFlutterBinding binding = tester.binding;