Button constructor
const
Button({
- Key? key,
- WidgetStatesController? statesController,
- Widget? leading,
- Widget? trailing,
- required Widget child,
- VoidCallback? onPressed,
- FocusNode? focusNode,
- AlignmentGeometry? alignment,
- required AbstractButtonStyle style,
- bool? enabled,
- bool disableTransition = false,
- ValueChanged<
bool> ? onFocus, - ValueChanged<
bool> ? onHover, - bool disableHoverEffect = false,
- 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,
- AlignmentGeometry? marginAlignment,
- bool disableFocusOutline = false,
Creates a Button with custom styling.
This is the base constructor that allows complete customization of the button's
appearance and behavior through the style
parameter. For common use cases,
consider using the named constructors like Button.primary or Button.secondary.
Parameters:
statesController
(WidgetStatesController?, optional): External state management.leading
(Widget?, optional): Widget displayed before the main content.trailing
(Widget?, optional): Widget displayed after the main content.child
(Widget, required): Main content of the button.onPressed
(VoidCallback?, optional): Primary action callback.focusNode
(FocusNode?, optional): Focus management node.alignment
(AlignmentGeometry?, optional): Content alignment within button.style
(AbstractButtonStyle, required): Visual styling configuration.enabled
(bool?, optional): Whether button responds to interactions.disableTransition
(bool, default: false): Whether to disable state animations.onFocus
(ValueChangedonHover
(ValueChangeddisableHoverEffect
(bool, default: false): Whether to disable hover visuals.enableFeedback
(bool?, optional): Whether to provide haptic feedback.marginAlignment
(AlignmentGeometry?, optional): Margin positioning.disableFocusOutline
(bool, default: false): Whether to hide focus outline.
Example:
Button(
style: ButtonStyle.primary(),
leading: Icon(Icons.save),
onPressed: () => saveDocument(),
child: Text('Save Document'),
);
Implementation
const Button({
super.key,
this.statesController,
this.leading,
this.trailing,
required this.child,
this.onPressed,
this.focusNode,
this.alignment,
required this.style,
this.enabled,
this.disableTransition = false,
this.onFocus,
this.onHover,
this.disableHoverEffect = false,
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.marginAlignment,
this.disableFocusOutline = false,
});