SelectedButton constructor

const SelectedButton({
  1. Key? key,
  2. required bool value,
  3. ValueChanged<bool>? onChanged,
  4. required Widget child,
  5. bool? enabled,
  6. AbstractButtonStyle style = const ButtonStyle.ghost(),
  7. AbstractButtonStyle selectedStyle = const ButtonStyle.secondary(),
  8. AlignmentGeometry? alignment,
  9. AlignmentGeometry? marginAlignment,
  10. bool disableTransition = false,
  11. ValueChanged<bool>? onHover,
  12. ValueChanged<bool>? onFocus,
  13. bool? enableFeedback,
  14. GestureTapDownCallback? onTapDown,
  15. GestureTapUpCallback? onTapUp,
  16. GestureTapCancelCallback? onTapCancel,
  17. GestureTapDownCallback? onSecondaryTapDown,
  18. GestureTapUpCallback? onSecondaryTapUp,
  19. GestureTapCancelCallback? onSecondaryTapCancel,
  20. GestureTapDownCallback? onTertiaryTapDown,
  21. GestureTapUpCallback? onTertiaryTapUp,
  22. GestureTapCancelCallback? onTertiaryTapCancel,
  23. GestureLongPressStartCallback? onLongPressStart,
  24. GestureLongPressUpCallback? onLongPressUp,
  25. GestureLongPressMoveUpdateCallback? onLongPressMoveUpdate,
  26. GestureLongPressEndCallback? onLongPressEnd,
  27. GestureLongPressUpCallback? onSecondaryLongPress,
  28. GestureLongPressUpCallback? onTertiaryLongPress,
  29. bool disableHoverEffect = false,
  30. WidgetStatesController? statesController,
  31. VoidCallback? onPressed,
})

Creates a SelectedButton widget.

A button that toggles between selected and unselected states, applying different styles based on the current value.

Parameters:

  • value (required): The current selection state (true for selected).
  • onChanged: Callback invoked when the selection state changes. If null, the button is disabled.
  • child (required): The widget displayed inside the button.
  • enabled: Whether the button is enabled. Defaults to checking if onChanged is non-null.
  • style: Style applied when unselected. Defaults to ButtonStyle.ghost.
  • selectedStyle: Style applied when selected. Defaults to ButtonStyle.secondary.
  • alignment: Alignment of the child within the button.
  • marginAlignment: Margin alignment for the button.
  • disableTransition: If true, disables style transition animations. Defaults to false.
  • onHover: Called when the hover state changes.
  • onFocus: Called when the focus state changes.
  • enableFeedback: Whether to enable haptic/audio feedback.
  • onTapDown, onTapUp, onTapCancel: Primary tap gesture callbacks.
  • onSecondaryTapDown, onSecondaryTapUp, onSecondaryTapCancel: Secondary tap gesture callbacks.
  • onTertiaryTapDown, onTertiaryTapUp, onTertiaryTapCancel: Tertiary tap gesture callbacks.
  • onLongPressStart, onLongPressUp, onLongPressMoveUpdate, onLongPressEnd: Long press gesture callbacks.
  • onSecondaryLongPress, onTertiaryLongPress: Secondary and tertiary long press callbacks.
  • disableHoverEffect: If true, disables the hover effect. Defaults to false.
  • statesController: Optional controller for programmatic state management.
  • onPressed: Called when the button is tapped.

Example:

SelectedButton(
  value: isSelected,
  onChanged: (selected) => setState(() => isSelected = selected),
  child: Text('Toggle Me'),
)

Implementation

const SelectedButton({
  super.key,
  required this.value,
  this.onChanged,
  required this.child,
  this.enabled,
  this.style = const ButtonStyle.ghost(),
  this.selectedStyle = const ButtonStyle.secondary(),
  this.alignment,
  this.marginAlignment,
  this.disableTransition = false,
  this.onHover,
  this.onFocus,
  this.enableFeedback,
  this.onTapDown,
  this.onTapUp,
  this.onTapCancel,
  this.onSecondaryTapDown,
  this.onSecondaryTapUp,
  this.onSecondaryTapCancel,
  this.onTertiaryTapDown,
  this.onTertiaryTapUp,
  this.onTertiaryTapCancel,
  this.onLongPressStart,
  this.onLongPressUp,
  this.onLongPressMoveUpdate,
  this.onLongPressEnd,
  this.onSecondaryLongPress,
  this.onTertiaryLongPress,
  this.disableHoverEffect = false,
  this.statesController,
  this.onPressed,
});