Skip to content

Commit

Permalink
Toggle buttons: themable title and subtitle text style (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Nov 25, 2022
1 parent a51cff8 commit 976a72b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/src/controls/yaru_toggle_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class YaruToggleButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = YaruToggleButtonTheme.of(context);
final textTheme = Theme.of(context).textTheme;

return MergeSemantics(
child: Semantics(
child: GestureDetector(
Expand All @@ -57,14 +59,14 @@ class YaruToggleButton extends StatelessWidget {
title: _wrapTextStyle(
context,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleMedium!,
style: theme?.titleStyle ?? textTheme.titleMedium!,
child: title,
),
subtitle: subtitle != null
? _wrapTextStyle(
context,
softWrap: true,
style: Theme.of(context).textTheme.bodySmall!,
style: theme?.subtitleStyle ?? textTheme.bodySmall!,
child: subtitle!,
)
: null,
Expand Down
25 changes: 23 additions & 2 deletions lib/src/controls/yaru_toggle_button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class YaruToggleButtonThemeData with Diagnosticable {
const YaruToggleButtonThemeData({
this.horizontalSpacing,
this.verticalSpacing,
this.titleStyle,
this.subtitleStyle,
});

/// The spacing between the indicator and the title.
Expand All @@ -20,27 +22,46 @@ class YaruToggleButtonThemeData with Diagnosticable {
/// The spacing between the title and the subtitle.
final double? verticalSpacing;

/// The style of the title text.
final TextStyle? titleStyle;

/// The style of the subtitle text.
final TextStyle? subtitleStyle;

/// Creates a copy with the given fields replaced with new values.
YaruToggleButtonThemeData copyWith({
double? horizontalSpacing,
double? verticalSpacing,
TextStyle? titleStyle,
TextStyle? subtitleStyle,
}) {
return YaruToggleButtonThemeData(
horizontalSpacing: horizontalSpacing ?? this.horizontalSpacing,
verticalSpacing: verticalSpacing ?? this.verticalSpacing,
titleStyle: titleStyle ?? this.titleStyle,
subtitleStyle: subtitleStyle ?? this.subtitleStyle,
);
}

@override
int get hashCode => Object.hash(horizontalSpacing, verticalSpacing);
int get hashCode {
return Object.hash(
horizontalSpacing,
verticalSpacing,
titleStyle,
subtitleStyle,
);
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
return other is YaruToggleButtonThemeData &&
other.horizontalSpacing == horizontalSpacing &&
other.verticalSpacing == verticalSpacing;
other.verticalSpacing == verticalSpacing &&
other.titleStyle == titleStyle &&
other.subtitleStyle == subtitleStyle;
}
}

Expand Down

0 comments on commit 976a72b

Please sign in to comment.