ModulaLoadingButton class
A button component that handles async operations with loading states.
The ModulaLoadingButton provides a complete button implementation with:
- Async operation support via onPressedAsync
- Automatic loading state management
- Full customization (colors, sizes, icons, etc.)
- Loading indicators with optional text
- Consistent with ModulaPrimaryButton design patterns
Example:
ModulaLoadingButton(
label: 'Submit',
icon: Icon(Icons.send),
onPressedAsync: () async {
await Future.delayed(Duration(seconds: 2));
},
size: ModulaButtonSize.medium,
loadingText: 'Submitting...',
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ModulaLoadingButton
Constructors
-
ModulaLoadingButton({Key? key, VoidCallback? onPressed, Future<
void> onPressedAsync()?, String? label, Widget? icon, IconPlacement iconPlacement = IconPlacement.left, TextStyle? labelStyle, ModulaButtonSize size = ModulaButtonSize.medium, bool isDisabled = false, double? borderRadius, Color? backgroundColor, Color? foregroundColor, Color? loadingColor, TextAlign textAlign = TextAlign.center, EdgeInsetsGeometry? padding, double? elevation, String? loadingText, Widget? loadingIndicator, bool showIconWhileLoading = false}) -
const
Properties
- backgroundColor → Color?
-
Background color of the button.
If not provided, uses theme's primary color.
final
- borderRadius → double?
-
Custom border radius for the button.
If not provided, defaults to 12.0.
final
- elevation → double?
-
Elevation of the button.
Defaults to 0.
final
- foregroundColor → Color?
-
Color of the button text and icon.
If not provided, defaults to white.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- icon → Widget?
-
Icon to display alongside the label.
final
- iconPlacement → IconPlacement
-
Position of the icon relative to the label.
Defaults to IconPlacement.left.
final
- isDisabled → bool
-
Whether the button is disabled.
Defaults to false.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- label → String?
-
The button label text.
final
- labelStyle → TextStyle?
-
Custom text style for the label.
final
- loadingColor → Color?
-
Color of the loading indicator.
If not provided, uses foregroundColor.
final
- loadingIndicator → Widget?
-
Custom loading indicator widget.
If not provided, uses a CircularProgressIndicator.
final
- loadingText → String?
-
Optional text to show during loading state.
If provided, shows next to loading indicator.
final
- onPressed → VoidCallback?
-
Synchronous callback when button is pressed.
Either onPressed or onPressedAsync must be provided.
final
-
onPressedAsync
→ Future<
void> Function()? -
Asynchronous callback when button is pressed.
The button will show loading state while this is executing.
Either onPressed or onPressedAsync must be provided.
final
- padding → EdgeInsetsGeometry?
-
Custom padding for the button.
If not provided, uses size-based defaults.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showIconWhileLoading → bool
-
Whether to show the icon while loading.
Defaults to false.
final
- size → ModulaButtonSize
-
Button size preset (small, medium, large).
Defaults to ModulaButtonSize.medium.
final
- textAlign → TextAlign
-
Text alignment for the label.
Defaults to TextAlign.center.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ModulaLoadingButton> -
Creates the mutable state for this widget at a given location in the tree.
override
-
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