Skip to content

Commit

Permalink
migrate away from value in Color
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian-Samoticha committed Jan 8, 2025
1 parent f34ae3e commit 8e93cd2
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.1.3"
version: "2.1.4"
macos_window_utils:
dependency: transitive
description:
Expand Down
10 changes: 8 additions & 2 deletions lib/src/buttons/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,16 @@ class _MacosSwitchState extends State<MacosSwitch>
final MacosThemeData theme = MacosTheme.of(context);
MacosColor borderColor =
MacosDynamicColor.resolve(_kDefaultBorderColor, context).toMacosColor();
MacosColor activeColor = MacosColor(MacosDynamicColor.resolve(
final resolvedActiveColor = MacosDynamicColor.resolve(
widget.activeColor ?? theme.primaryColor,
context,
).value);
);
MacosColor activeColor = MacosColor.fromRGBO(
(resolvedActiveColor.r * 255).toInt(),
(resolvedActiveColor.g * 255).toInt(),
(resolvedActiveColor.b * 255).toInt(),
resolvedActiveColor.a,
);
MacosColor trackColor = widget.trackColor ??
MacosDynamicColor.resolve(_kDefaultTrackColor, context).toMacosColor();
MacosColor knobColor = widget.knobColor ??
Expand Down
2 changes: 1 addition & 1 deletion lib/src/icon/image_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MacosImageIcon extends StatelessWidget {
Color iconColor = color ?? iconTheme.color!;

if (iconOpacity != null && iconOpacity != 1.0) {
iconColor = iconColor.withValues(alpha: iconColor.opacity * iconOpacity);
iconColor = iconColor.withValues(alpha: iconColor.a * iconOpacity);
}

return Semantics(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/icon/macos_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class MacosIcon extends StatelessWidget {
final iconOpacity = iconTheme.opacity ?? 1.0;
Color iconColor = color ?? iconTheme.color!;
if (iconOpacity != 1.0) {
iconColor = iconColor.withValues(alpha: iconColor.opacity * iconOpacity);
iconColor = iconColor.withValues(alpha: iconColor.a * iconOpacity);
}

Widget iconWidget = RichText(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layout/title_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TitleBar extends StatelessWidget {
),
child: ClipRect(
child: BackdropFilter(
filter: decoration?.color?.opacity == 1
filter: decoration?.color?.a == 1
? ImageFilter.blur()
: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
child: Container(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layout/toolbar/toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class _ToolBarState extends State<ToolBar> {
enableWallpaperTintedArea: kIsWeb ? false : !widget.enableBlur,
isWidgetVisible: widget.allowWallpaperTintingOverrides,
backgroundColor: theme.canvasColor,
widgetOpacity: widget.decoration?.color?.opacity,
widgetOpacity: widget.decoration?.color?.a,
child: Container(
alignment: widget.alignment,
padding: widget.padding,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/theme/help_button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class HelpButtonThemeData with Diagnosticable {
return identical(this, other) ||
other is HelpButtonThemeData &&
runtimeType == other.runtimeType &&
color?.value == other.color?.value &&
disabledColor?.value == other.disabledColor?.value;
color == other.color &&
disabledColor == other.disabledColor;
}

@override
Expand Down
6 changes: 3 additions & 3 deletions lib/src/theme/icon_button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class MacosIconButtonThemeData with Diagnosticable {
identical(this, other) ||
other is MacosIconButtonThemeData &&
runtimeType == other.runtimeType &&
backgroundColor?.value == other.backgroundColor?.value &&
disabledColor?.value == other.disabledColor?.value &&
hoverColor?.value == other.hoverColor?.value &&
backgroundColor == other.backgroundColor &&
disabledColor == other.disabledColor &&
hoverColor == other.hoverColor &&
shape == other.shape &&
borderRadius == other.borderRadius &&
boxConstraints == other.boxConstraints &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/theme/icon_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class MacosIconThemeData with Diagnosticable {
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) return false;
return other is MacosIconThemeData &&
other.color?.value == color?.value &&
other.color == color &&
other.opacity == opacity &&
other.size == size;
}
Expand Down
23 changes: 16 additions & 7 deletions lib/src/theme/macos_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ class MacosColor extends Color {
/// Linearly interpolate between two [MacosColor]s.
static MacosColor lerp(MacosColor a, MacosColor b, double t) {
final Color? color = Color.lerp(a, b, t);
return MacosColor(color!.value);
return MacosColor.fromRGBO(
(color!.r * 255).toInt(),
(color.g * 255).toInt(),
(color.b * 255).toInt(),
color.a,
);
}

/// Combine the foreground color as a transparent color over top
Expand Down Expand Up @@ -139,22 +144,26 @@ class MacosColor extends Color {
if (other.runtimeType != runtimeType) {
return false;
}
return other is MacosColor && other.value == value;
return other is MacosColor && other.hashCode == hashCode;
}

@override
int get hashCode => value.hashCode;
int get hashCode => Object.hash(r, g, b, a);

@override
String toString() {
return 'MacosColor(0x${value.toRadixString(16).padLeft(8, '0')})';
}
String toString() =>
'MacosColor(alpha: ${a.toStringAsFixed(4)}, red: ${r.toStringAsFixed(4)}, green: ${g.toStringAsFixed(4)}, blue: ${b.toStringAsFixed(4)}, colorSpace: $colorSpace)';
}

extension ColorX on Color {
/// Returns a [MacosColor] with the same color values as this [Color].
MacosColor toMacosColor() {
return MacosColor(value);
return MacosColor.fromRGBO(
(r * 255).floor(),
(g * 255).floor(),
(b * 255).floor(),
a,
);
}
}

Expand Down
3 changes: 0 additions & 3 deletions lib/src/theme/macos_dynamic_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ class ResolvedMacosDynamicColor extends CupertinoDynamicColor {

final Color resolvedColor;

@override
int get value => resolvedColor.value;

@override
double get r => resolvedColor.r;

Expand Down
6 changes: 3 additions & 3 deletions lib/src/theme/popup_button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ class MacosPopupButtonThemeData with Diagnosticable {
identical(this, other) ||
other is MacosPopupButtonThemeData &&
runtimeType == other.runtimeType &&
highlightColor?.value == other.highlightColor?.value &&
backgroundColor?.value == other.backgroundColor?.value &&
popupColor?.value == other.popupColor?.value;
highlightColor == other.highlightColor &&
backgroundColor == other.backgroundColor &&
popupColor == other.popupColor;

@override
int get hashCode => highlightColor.hashCode ^ backgroundColor.hashCode;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/theme/pulldown_button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ class MacosPulldownButtonThemeData with Diagnosticable {
identical(this, other) ||
other is MacosPulldownButtonThemeData &&
runtimeType == other.runtimeType &&
highlightColor?.value == other.highlightColor?.value &&
backgroundColor?.value == other.backgroundColor?.value &&
pulldownColor?.value == other.pulldownColor?.value &&
iconColor?.value == other.iconColor?.value;
highlightColor == other.highlightColor &&
backgroundColor == other.backgroundColor &&
pulldownColor == other.pulldownColor &&
iconColor == other.iconColor;

@override
int get hashCode => highlightColor.hashCode ^ backgroundColor.hashCode;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/theme/search_field_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class MacosSearchFieldThemeData with Diagnosticable {
identical(this, other) ||
other is MacosSearchFieldThemeData &&
runtimeType == other.runtimeType &&
highlightColor?.value == other.highlightColor?.value &&
resultsBackgroundColor?.value == other.resultsBackgroundColor?.value;
highlightColor == other.highlightColor &&
resultsBackgroundColor == other.resultsBackgroundColor;

@override
int get hashCode => highlightColor.hashCode ^ resultsBackgroundColor.hashCode;
Expand Down

0 comments on commit 8e93cd2

Please sign in to comment.