diff --git a/lib/src/themes/common_themes.dart b/lib/src/themes/common_themes.dart index bca14104..1d2fa2f3 100644 --- a/lib/src/themes/common_themes.dart +++ b/lib/src/themes/common_themes.dart @@ -359,13 +359,10 @@ SwitchThemeData _createSwitchTheme(ColorScheme colorScheme) { Color _getSwitchThumbColor(Set states, ColorScheme colorScheme) { if (states.contains(MaterialState.disabled)) { - if (states.contains(MaterialState.selected)) { - return colorScheme.onSurface.withOpacity(0.5); - } return colorScheme.onSurface.withOpacity(0.5); - } else { - return colorScheme.onPrimary; } + + return colorScheme.onPrimary; } Color _getSwitchTrackColor(Set states, ColorScheme colorScheme) { @@ -373,43 +370,41 @@ Color _getSwitchTrackColor(Set states, ColorScheme colorScheme) { final disabledUncheckedColor = colorScheme.onSurface.withOpacity(.15); final disabledCheckedColor = colorScheme.onSurface.withOpacity(.18); + if (states.containsAll([MaterialState.disabled, MaterialState.selected])) { + return disabledCheckedColor; + } + if (states.contains(MaterialState.disabled)) { - if (states.contains(MaterialState.selected)) { - return disabledCheckedColor; - } return disabledUncheckedColor; - } else { - if (states.contains(MaterialState.selected)) { - return colorScheme.primary; - } else { - return uncheckedColor; - } } + + if (states.contains(MaterialState.selected)) { + return colorScheme.primary; + } + + return uncheckedColor; } // Checks & Radios Color _getCheckFillColor(Set states, ColorScheme colorScheme) { - if (!states.contains(MaterialState.disabled)) { - if (states.contains(MaterialState.selected)) { - return colorScheme.primary; - } - return colorScheme.onSurface.withOpacity(0.75); + if (states.contains(MaterialState.disabled)) { + return colorScheme.onSurface.withOpacity(0.2); } + if (states.contains(MaterialState.selected)) { - return colorScheme.onSurface.withOpacity(0.2); + return colorScheme.primary; } - return colorScheme.onSurface.withOpacity(0.2); + + return colorScheme.onSurface.withOpacity(0.75); } Color _getCheckColor(Set states, ColorScheme colorScheme) { - if (!states.contains(MaterialState.disabled)) { - return ThemeData.estimateBrightnessForColor(colorScheme.primary) == - Brightness.light - ? Colors.black - : Colors.white; + if (states.contains(MaterialState.disabled)) { + return YaruColors.warmGrey; } - return YaruColors.warmGrey; + + return contrastColor(colorScheme.primary); } CheckboxThemeData _createCheckBoxTheme(ColorScheme colorScheme) { @@ -494,12 +489,11 @@ SliderThemeData _createSliderTheme(ColorScheme colorScheme) { ); } -Color contrastColor(Color color) => ThemeData.estimateBrightnessForColor( - color, - ) == - Brightness.light - ? Colors.black - : Colors.white; +Color contrastColor(Color color) { + final brightness = ThemeData.estimateBrightnessForColor(color); + + return brightness == Brightness.dark ? Colors.white : Colors.black; +} PopupMenuThemeData _createPopupMenuTheme(ColorScheme colorScheme) { final bgColor = diff --git a/lib/src/widgets/inherited_theme.dart b/lib/src/widgets/inherited_theme.dart index 7e4784fd..8751ae4e 100644 --- a/lib/src/widgets/inherited_theme.dart +++ b/lib/src/widgets/inherited_theme.dart @@ -172,13 +172,18 @@ class _YaruThemeState extends State { } ThemeMode resolveMode() { - final mode = widget.data.themeMode ?? ThemeMode.system; - if (mode == ThemeMode.system) { - return MediaQuery.platformBrightnessOf(context) == Brightness.dark - ? ThemeMode.dark - : ThemeMode.light; + final mode = widget.data.themeMode; + if (mode != null) { + return mode; } - return mode; + + final brightness = MediaQuery.platformBrightnessOf(context); + + if (brightness == Brightness.dark) { + return ThemeMode.dark; + } + + return ThemeMode.light; } YaruThemeData resolveData() { @@ -206,6 +211,7 @@ class _YaruThemeState extends State { if (_settings != null && _subscription == null) { return const SizedBox.shrink(); // #231 } + final data = resolveData(); return _YaruInheritedTheme( data: data,