Skip to content

Commit

Permalink
Ignore secondary color when it matches the primary color
Browse files Browse the repository at this point in the history
This is the default by material themes
  • Loading branch information
passsy committed Apr 21, 2022
1 parent 2beb564 commit a9222de
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/src/core/theme/wiredash_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,41 @@ class WiredashThemeData {
Color? secondaryColor,
required Brightness brightness,
}) {
final hsl = HSLColor.fromColor(primaryColor);
if (secondaryColor?.value == primaryColor.value) {
secondaryColor = null;
}
final primaryHsl = HSLColor.fromColor(primaryColor);

final theme =
WiredashThemeData(brightness: brightness, primaryColor: primaryColor);

if (brightness == Brightness.light) {
final secondary = secondaryColor ??
hsl
.withHue((hsl.hue - 10) % 360)
primaryHsl
.withHue((primaryHsl.hue - 10) % 360)
.withSaturation(.60)
.withLightness(.90)
.toColor();
return theme.copyWith(
secondaryColor: secondary,
primaryBackgroundColor:
hsl.withSaturation(1.0).withLightness(1.0).toColor(),
primaryHsl.withSaturation(1.0).withLightness(1.0).toColor(),
secondaryBackgroundColor:
hsl.withSaturation(.8).withLightness(0.95).toColor(),
primaryHsl.withSaturation(.8).withLightness(0.95).toColor(),
);
} else {
final secondary = secondaryColor ??
hsl
.withHue((hsl.hue - 10) % 360)
primaryHsl
.withHue((primaryHsl.hue - 10) % 360)
.withSaturation(.1)
.withLightness(.1)
.toColor();
return theme.copyWith(
secondaryColor: secondary,
primaryBackgroundColor:
hsl.withSaturation(0.04).withLightness(0.2).toColor(),
primaryHsl.withSaturation(0.04).withLightness(0.2).toColor(),
secondaryBackgroundColor:
hsl.withSaturation(0.0).withLightness(0.1).toColor(),
primaryHsl.withSaturation(0.0).withLightness(0.1).toColor(),
);
}
}
Expand Down

0 comments on commit a9222de

Please sign in to comment.