SelectedButton constructor
const
SelectedButton({
- Key? key,
- required bool value,
- ValueChanged<
bool> ? onChanged, - required Widget child,
- bool? enabled,
- AbstractButtonStyle style = const ButtonStyle.ghost(),
- AbstractButtonStyle selectedStyle = const ButtonStyle.secondary(),
- AlignmentGeometry? alignment,
- AlignmentGeometry? marginAlignment,
- bool disableTransition = false,
- ValueChanged<
bool> ? onHover, - ValueChanged<
bool> ? onFocus, - bool? enableFeedback,
- GestureTapDownCallback? onTapDown,
- GestureTapUpCallback? onTapUp,
- GestureTapCancelCallback? onTapCancel,
- GestureTapDownCallback? onSecondaryTapDown,
- GestureTapUpCallback? onSecondaryTapUp,
- GestureTapCancelCallback? onSecondaryTapCancel,
- GestureTapDownCallback? onTertiaryTapDown,
- GestureTapUpCallback? onTertiaryTapUp,
- GestureTapCancelCallback? onTertiaryTapCancel,
- GestureLongPressStartCallback? onLongPressStart,
- GestureLongPressUpCallback? onLongPressUp,
- GestureLongPressMoveUpdateCallback? onLongPressMoveUpdate,
- GestureLongPressEndCallback? onLongPressEnd,
- GestureLongPressUpCallback? onSecondaryLongPress,
- GestureLongPressUpCallback? onTertiaryLongPress,
- bool disableHoverEffect = false,
- WidgetStatesController? statesController,
- 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 (truefor selected).onChanged: Callback invoked when the selection state changes. Ifnull, the button is disabled.child(required): The widget displayed inside the button.enabled: Whether the button is enabled. Defaults to checking ifonChangedis 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: Iftrue, disables style transition animations. Defaults tofalse.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: Iftrue, disables the hover effect. Defaults tofalse.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,
});