Skip to content

Commit c21c70a

Browse files
committed
button: Implement a disabled state for Toggle
Vlad suggested using 0.5 opacity if no special disabled state is provided: https://chat.zulip.org/#narrow/channel/530-mobile-design/topic/toggle.3A.20disabled.20state/near/2250883 but Greg and I prefer 0.4 in this case to make it more distinct. We may or may not end up using this for unsubscribed channels without content access (i.e. ones that you can't subscribe yourself to). We may instead just not show a toggle for those channels.
1 parent 833aeb2 commit c21c70a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/widgets/button.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ enum ZulipMenuItemButtonStyle {
477477

478478
/// The "toggle" component in Figma.
479479
///
480+
/// If [onChanged] is null, the switch will be displayed as disabled.
481+
/// (Like in the Material [Switch] widget.)
482+
///
480483
/// See Figma:
481484
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6070-60682&m=dev
482485
class Toggle extends StatelessWidget {
@@ -487,18 +490,29 @@ class Toggle extends StatelessWidget {
487490
});
488491

489492
final bool value;
490-
final ValueChanged<bool> onChanged;
493+
final ValueChanged<bool>? onChanged;
491494

492495
@override
493496
Widget build(BuildContext context) {
494497
// Figma has this (blue/500) in both light and dark mode.
495498
// TODO(#831)
496499
final activeColor = Color(0xff4370f0);
497500

501+
final activeColorDisabled = activeColor.withFadedAlpha(0.4);
502+
498503
// Figma has this (grey/400) in both light and dark mode.
499504
// TODO(#831)
500505
final inactiveColor = Color(0xff9194a3);
501506

507+
final inactiveColorDisabled = inactiveColor.withFadedAlpha(0.4);
508+
509+
final trackColor = WidgetStateColor.fromMap({
510+
WidgetState.selected & ~WidgetState.disabled: activeColor,
511+
WidgetState.selected & WidgetState.disabled: activeColorDisabled,
512+
~WidgetState.selected & ~WidgetState.disabled: inactiveColor,
513+
~WidgetState.selected & WidgetState.disabled: inactiveColorDisabled,
514+
});
515+
502516
// TODO(#1636):
503517
// All of these just need _SwitchConfig to be exposed,
504518
// and there's an upstream issue for that:
@@ -524,8 +538,7 @@ class Toggle extends StatelessWidget {
524538
// Figma has white for "on" and "off" in both light and dark mode.
525539
thumbColor: WidgetStatePropertyAll(Colors.white),
526540

527-
activeTrackColor: activeColor,
528-
inactiveTrackColor: inactiveColor,
541+
trackColor: trackColor,
529542
trackOutlineColor: WidgetStatePropertyAll(Colors.transparent),
530543
trackOutlineWidth: WidgetStateProperty<double>.fromMap({
531544
// The outline is effectively painted with strokeAlignCenter:

0 commit comments

Comments
 (0)