XButton class
A customizable button supporting idle, loading, success, and error states, icons, custom content, rounded style, and native button configuration.
The XButton is designed to simplify button creation with flexible styling using XButtonStyle. It supports prefix, center, and suffix icons, loading indicator, disabled state, and forced tap functionality.
This widget is suitable for most general button use-cases in Flutter apps.
Example:
XButton(
label: "Submit",
onPressed: () {},
style: XButtonStyle(background: Colors.blue),
);
// Opt into a look preset (default is [XLook.standard]):
XButton(label: 'Save', onPressed: () {}, look: XLook.ios);
- Inheritance
Constructors
-
XButton({Key? key, required Function onPressed, VoidCallback? onLongPress, ValueChanged<
bool> ? onHover, ValueChanged<bool> ? onFocusChange, String? label, double? radius, XButtonStyle? style, ButtonStyle? elevatedButtonStyle, FocusNode? focusNode, bool autofocus = false, Clip? clipBehavior, WidgetStatesController? statesController, TextStyle? textStyle, XButtonState? state, bool isLoading = false, bool isLoadingInside = false, String? loadingLabel, String successLabel = 'Success', String errorLabel = 'Try again', Widget? loadingChild, Widget? successChild, Widget? errorChild, Widget? loadingIndicator, Widget successIcon = const Icon(Icons.check), Widget errorIcon = const Icon(Icons.refresh), Duration stateTransitionDuration = const Duration(milliseconds: 200), bool isEnable = true, bool? isForceTap = false, Widget? child, double? width, double? height, bool widthInfinity = false, XLook look = XLook.standard}) -
const
Properties
- autofocus → bool
-
Whether this button should be focused initially.
final
- child → Widget?
-
Custom widget to replace the label text, useful for advanced text layouts.
final
- clipBehavior → Clip?
-
The clipping behavior of the button's content.
final
- elevatedButtonStyle → ButtonStyle?
-
Native ButtonStyle for ElevatedButton.
final
- errorChild → Widget?
-
Fully custom content for XButtonState.error.
final
- errorIcon → Widget
-
Icon used by the default error content.
final
- errorLabel → String
-
Default label for XButtonState.error.
final
- focusNode → FocusNode?
-
Optional focus node for ElevatedButton.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
Custom height of the button. Defaults to 48.
final
- isEnable → bool
-
Controls whether the button is enabled.
final
- isForceTap → bool?
-
Force the onPressed function to run even when isEnable is false.
final
- isLoading → bool
-
Whether to show a loading indicator instead of the button.
final
- isLoadingInside → bool
-
Whether a legacy isLoading indicator remains inside ElevatedButton.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- label → String?
-
Text label displayed on the button.
final
- loadingChild → Widget?
-
Fully custom content for XButtonState.loading.
final
- loadingIndicator → Widget?
-
Custom indicator used by the default loading content.
final
- loadingLabel → String?
-
Optional label shown beside the default loading indicator.
final
- look → XLook
-
Visual look preset. Defaults to XLook.standard (existing package look).
final
-
onFocusChange
→ ValueChanged<
bool> ? -
Called when the button gains or loses focus.
final
-
onHover
→ ValueChanged<
bool> ? -
Called when a pointer enters or exits the button.
final
- onLongPress → VoidCallback?
-
Called when the button is long-pressed.
final
- onPressed → Function
-
Called when the button is tapped.
final
- radius → double?
-
Border radius for the button shape.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → XButtonState?
-
Explicit visual state controlled by application state.
final
- statesController → WidgetStatesController?
-
Optional states controller for ElevatedButton.
final
- stateTransitionDuration → Duration
-
Animation duration when state changes.
final
- style → XButtonStyle?
-
Custom style configuration for the button.
final
- successChild → Widget?
-
Fully custom content for XButtonState.success.
final
- successIcon → Widget
-
Icon used by the default success content.
final
- successLabel → String
-
Default label for XButtonState.success.
final
- textStyle → TextStyle?
-
final
- width → double?
-
final
- widthInfinity → bool
-
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited