Skip to content

Commit

Permalink
Separate theme logic (#117818)
Browse files Browse the repository at this point in the history
Separate theme logic
  • Loading branch information
MahanRahmati authored Feb 27, 2023
1 parent fa49db3 commit 14a9c23
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/flutter/lib/src/material/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -910,15 +910,14 @@ class _MaterialAppState extends State<MaterialApp> {
);
}

Widget _materialBuilder(BuildContext context, Widget? child) {
ThemeData _themeBuilder(BuildContext context) {
ThemeData? theme;
// Resolve which theme to use based on brightness and high contrast.
final ThemeMode mode = widget.themeMode ?? ThemeMode.system;
final Brightness platformBrightness = MediaQuery.platformBrightnessOf(context);
final bool useDarkTheme = mode == ThemeMode.dark
|| (mode == ThemeMode.system && platformBrightness == ui.Brightness.dark);
final bool highContrast = MediaQuery.highContrastOf(context);
ThemeData? theme;

if (useDarkTheme && highContrast && widget.highContrastDarkTheme != null) {
theme = widget.highContrastDarkTheme;
} else if (useDarkTheme && widget.darkTheme != null) {
Expand All @@ -927,6 +926,11 @@ class _MaterialAppState extends State<MaterialApp> {
theme = widget.highContrastTheme;
}
theme ??= widget.theme ?? ThemeData.light();
return theme;
}

Widget _materialBuilder(BuildContext context, Widget? child) {
final ThemeData theme = _themeBuilder(context);
final Color effectiveSelectionColor = theme.textSelectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
final Color effectiveCursorColor = theme.textSelectionTheme.cursorColor ?? theme.colorScheme.primary;

Expand Down

0 comments on commit 14a9c23

Please sign in to comment.