Skip to content

Commit

Permalink
refactor: equality operators
Browse files Browse the repository at this point in the history
  • Loading branch information
TesteurManiak committed Dec 20, 2023
1 parent 4d824e8 commit f4feee8
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/src/theme/radius.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class DSFRRadius extends ThemeExtension<DSFRRadius> {
return DSFRRadius._(small: Radius.lerp(small, other.small, t)!);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRRadius &&
runtimeType == other.runtimeType &&
small == other.small;
}

@override
int get hashCode => Object.hash(runtimeType, small);

@visibleForTesting
List<NamedProperty<Radius>> get props => [
NamedProperty('small', small),
];
Expand All @@ -44,4 +56,15 @@ class DSFRBorderRadius extends ThemeExtension<DSFRBorderRadius> {
if (other is! DSFRBorderRadius) return this;
return DSFRBorderRadius(_radius.lerp(other._radius, t));
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRBorderRadius &&
runtimeType == other.runtimeType &&
_radius == other._radius;
}

@override
int get hashCode => Object.hash(runtimeType, _radius);
}
44 changes: 44 additions & 0 deletions lib/src/theme/sizes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,50 @@ class DSFRSizes extends ThemeExtension<DSFRSizes> {
);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRSizes &&
runtimeType == other.runtimeType &&
v0_5 == other.v0_5 &&
v1 == other.v1 &&
v1_5 == other.v1_5 &&
w1 == other.w1 &&
v3 == other.v3 &&
w2 == other.w2 &&
v5 == other.v5 &&
w3 == other.w3 &&
w4 == other.w4 &&
w5 == other.w5 &&
w6 == other.w6 &&
w7 == other.w7 &&
w8 == other.w8 &&
w9 == other.w9 &&
w12 == other.w12 &&
w15 == other.w15;
}

@override
int get hashCode => Object.hash(
runtimeType,
v0_5,
v1,
v1_5,
w1,
v3,
w2,
v5,
w3,
w4,
w5,
w6,
w7,
w8,
w9,
w12,
w15,
);

@visibleForTesting
List<NamedProperty<double>> get props => [
NamedProperty('v0_5', v0_5),
Expand Down
67 changes: 67 additions & 0 deletions lib/src/theme/spacings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ class DSFRSpacings extends ThemeExtension<DSFRSpacings> {
radioSize: DSFRRadioSize.lerp(radioSize, other.radioSize, t)!,
);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRSpacings &&
runtimeType == other.runtimeType &&
badgeSize == other.badgeSize &&
buttonSize == other.buttonSize &&
radioSize == other.radioSize;
}

@override
int get hashCode {
return Object.hash(runtimeType, badgeSize, buttonSize, radioSize);
}
}

@immutable
Expand Down Expand Up @@ -100,6 +115,22 @@ class DSFRBadgeSize {
spacing: lerpDouble(a.spacing, b.spacing, t)!,
);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRBadgeSize &&
runtimeType == other.runtimeType &&
horizontal == other.horizontal &&
vertical == other.vertical &&
iconSize == other.iconSize &&
spacing == other.spacing;
}

@override
int get hashCode {
return Object.hash(runtimeType, horizontal, vertical, iconSize, spacing);
}
}

@immutable
Expand Down Expand Up @@ -162,6 +193,30 @@ class DSFRButtonSize {
iconSize: lerpDouble(a.iconSize, b.iconSize, t)!,
);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRButtonSize &&
runtimeType == other.runtimeType &&
vertical == other.vertical &&
horizontal == other.horizontal &&
spacing == other.spacing &&
iconPadding == other.iconPadding &&
iconSize == other.iconSize;
}

@override
int get hashCode {
return Object.hash(
runtimeType,
vertical,
horizontal,
spacing,
iconPadding,
iconSize,
);
}
}

@immutable
Expand All @@ -186,4 +241,16 @@ class DSFRRadioSize {
spacing: lerpDouble(a.spacing, b.spacing, t)!,
);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRRadioSize &&
runtimeType == other.runtimeType &&
size == other.size &&
spacing == other.spacing;
}

@override
int get hashCode => Object.hash(runtimeType, size, spacing);
}
26 changes: 26 additions & 0 deletions lib/src/theme/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,30 @@ class DSFRThemeData extends ThemeExtension<DSFRThemeData> {
typography: typography.lerp(other.typography, t),
);
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRThemeData &&
runtimeType == other.runtimeType &&
buttonStyle == other.buttonStyle &&
colors == other.colors &&
radius == other.radius &&
borderRadius == other.borderRadius &&
sizes == other.sizes &&
spacings == other.spacings &&
typography == other.typography;
}

@override
int get hashCode => Object.hash(
runtimeType,
buttonStyle,
colors,
radius,
borderRadius,
sizes,
spacings,
typography,
);
}
3 changes: 3 additions & 0 deletions lib/src/theme/theme_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import 'package:flutter/material.dart';

import '../../flutter_dsfr.dart';

/// {@template dsfr_theme_widget}
/// A widget that overrides the theme with the provided [theme] for its [child].
/// {@endtemplate}
class DSFRThemeWidget extends StatelessWidget {
final DSFRThemeData data;
final Widget child;

/// {@macro dsfr_theme_widget}
const DSFRThemeWidget({
super.key,
required this.data,
Expand Down
34 changes: 34 additions & 0 deletions lib/src/theme/typography.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,38 @@ class DSFRTypography extends ThemeExtension<DSFRTypography> {
NamedProperty('detail', detail),
NamedProperty('regular', regular),
];

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is DSFRTypography &&
runtimeType == other.runtimeType &&
frConnectLogin == other.frConnectLogin &&
frConnectBrand == other.frConnectBrand &&
frConnectGroup == other.frConnectGroup &&
alertsTitle == other.alertsTitle &&
defaultText == other.defaultText &&
boldText == other.boldText &&
medium == other.medium &&
mention == other.mention &&
detail == other.detail &&
regular == other.regular;
}

@override
int get hashCode {
return Object.hash(
runtimeType,
frConnectLogin,
frConnectBrand,
frConnectGroup,
alertsTitle,
defaultText,
boldText,
medium,
mention,
detail,
regular,
);
}
}

0 comments on commit f4feee8

Please sign in to comment.