Unverified Commit 643da4b7 authored by Rami's avatar Rami Committed by GitHub

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

parent c90c4b35
......@@ -655,11 +655,11 @@ class _MaterialAppState extends State<MaterialApp> {
final bool highContrast = MediaQuery.highContrastOf(context);
ThemeData theme;
if (useDarkTheme && highContrast) {
if (useDarkTheme && highContrast && widget.highContrastDarkTheme != null) {
theme = widget.highContrastDarkTheme;
} else if (useDarkTheme) {
} else if (useDarkTheme && widget.darkTheme != null) {
theme = widget.darkTheme;
} else if (highContrast) {
} else if (highContrast && widget.highContrastTheme != null) {
theme = widget.highContrastTheme;
}
theme ??= widget.theme ?? ThemeData.light();
......
......@@ -812,6 +812,34 @@ void main() {
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 {
// Mock the Window to explicitly report a light platformBrightness.
final TestWidgetsFlutterBinding binding = tester.binding;
......
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