Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
refactor: improved if readability
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLiux committed Oct 6, 2023
1 parent d85580f commit 3cfce6c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
60 changes: 27 additions & 33 deletions lib/src/themes/common_themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,57 +359,52 @@ SwitchThemeData _createSwitchTheme(ColorScheme colorScheme) {

Color _getSwitchThumbColor(Set<MaterialState> 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<MaterialState> states, ColorScheme colorScheme) {
final uncheckedColor = colorScheme.onSurface.withOpacity(.25);
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<MaterialState> 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<MaterialState> 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) {
Expand Down Expand Up @@ -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 =
Expand Down
18 changes: 12 additions & 6 deletions lib/src/widgets/inherited_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,18 @@ class _YaruThemeState extends State<YaruTheme> {
}

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() {
Expand Down Expand Up @@ -206,6 +211,7 @@ class _YaruThemeState extends State<YaruTheme> {
if (_settings != null && _subscription == null) {
return const SizedBox.shrink(); // #231
}

final data = resolveData();
return _YaruInheritedTheme(
data: data,
Expand Down

0 comments on commit 3cfce6c

Please sign in to comment.