Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow color customization of single togglable #527

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/src/controls/yaru_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class YaruCheckbox extends StatefulWidget implements YaruTogglable<bool?> {
required this.value,
this.tristate = false,
required this.onChanged,
this.selectedColor,
this.checkmarkColor,
this.focusNode,
this.autofocus = false,
}) : assert(tristate || value != null);
Expand Down Expand Up @@ -100,6 +102,18 @@ class YaruCheckbox extends StatefulWidget implements YaruTogglable<bool?> {
@override
final ValueChanged<bool?>? onChanged;

/// The color to use when this checkbox is checked.
///
/// Defaults to [ColorScheme.primary].
@override
final Color? selectedColor;

/// The color to use for the checkmark when this checkbox is checked.
///
/// Defaults to [ColorScheme.onPrimary].
@override
final Color? checkmarkColor;

@override
bool get interactive => onChanged != null;

Expand Down
14 changes: 14 additions & 0 deletions lib/src/controls/yaru_radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class YaruRadio<T> extends StatefulWidget implements YaruTogglable<T?> {
required this.groupValue,
this.toggleable = false,
required this.onChanged,
this.selectedColor,
this.checkmarkColor,
this.focusNode,
this.autofocus = false,
}) : assert(toggleable || value != null);
Expand Down Expand Up @@ -110,6 +112,18 @@ class YaruRadio<T> extends StatefulWidget implements YaruTogglable<T?> {
@override
final ValueChanged<T?>? onChanged;

/// The color to use when this radio is checked.
///
/// Defaults to [ColorScheme.primary].
@override
final Color? selectedColor;

/// The color to use for the checkmark when this radio is checked.
///
/// Defaults to [ColorScheme.onPrimary].
@override
final Color? checkmarkColor;

@override
bool get interactive => onChanged != null;

Expand Down
14 changes: 14 additions & 0 deletions lib/src/controls/yaru_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class YaruSwitch extends StatefulWidget implements YaruTogglable<bool> {
super.key,
required this.value,
required this.onChanged,
this.selectedColor,
this.checkmarkColor,
this.focusNode,
this.autofocus = false,
});
Expand Down Expand Up @@ -76,6 +78,18 @@ class YaruSwitch extends StatefulWidget implements YaruTogglable<bool> {
@override
final ValueChanged<bool>? onChanged;

/// The color to use when this switch is on.
///
/// Defaults to [ColorScheme.primary].
@override
final Color? selectedColor;

/// The color to use for the dot when this switch is on.
///
/// Defaults to [ColorScheme.onPrimary].
@override
final Color? checkmarkColor;

@override
bool get interactive => onChanged != null;

Expand Down
16 changes: 14 additions & 2 deletions lib/src/controls/yaru_togglable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ abstract class YaruTogglable<T> extends StatefulWidget {
required this.value,
this.tristate = false,
required this.onChanged,
this.selectedColor,
this.checkmarkColor,
this.focusNode,
this.autofocus = false,
});
Expand All @@ -45,6 +47,16 @@ abstract class YaruTogglable<T> extends StatefulWidget {
/// gets rebuilt.
final ValueChanged<T>? onChanged;

/// The color to use when this togglable is checked.
///
/// Defaults to [ColorScheme.primary].
final Color? selectedColor;

/// The color to use for the checkmark when this togglable is checked.
///
/// Defaults to [ColorScheme.onPrimary].
final Color? checkmarkColor;

/// Determine if this [YaruTogglable] can handle events.
bool get interactive;

Expand Down Expand Up @@ -236,8 +248,8 @@ abstract class YaruTogglableState<S extends YaruTogglable> extends State<S>
// Normal colors
final uncheckedColor = colorScheme.surface;
final uncheckedBorderColor = colorScheme.onSurface.withOpacity(.3);
final checkedColor = colorScheme.primary;
final checkmarkColor = colorScheme.onPrimary;
final checkedColor = widget.selectedColor ?? colorScheme.primary;
final checkmarkColor = widget.checkmarkColor ?? colorScheme.onPrimary;

// Disabled colors
final uncheckedDisabledColor = colorScheme.onSurface.withOpacity(.1);
Expand Down