Skip to content

Commit

Permalink
Allow color customization of single togglable (#527)
Browse files Browse the repository at this point in the history
Fixes #526
  • Loading branch information
Jupi007 committed Jan 15, 2023
1 parent c5cc3fb commit 6274160
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
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

0 comments on commit 6274160

Please sign in to comment.