SinglePressButton class
A customizable button that ensures the onPressed callback is invoked only once per press. It prevents multiple invocations during a single press, making it ideal for handling actions that shouldn't be executed multiple times concurrently, such as network requests.
The SinglePressButton provides options to display a loading indicator while processing, customize its appearance, and handle processing states with callbacks.
Example usage:
SinglePressButton(
onPressed: () async {
await performNetworkRequest();
},
child: Text('Submit'),
showLoadingIndicator: true,
color: Colors.blue,
disabledColor: Colors.blueAccent,
borderRadius: 12.0,
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
onStartProcessing: () {
// Optional: Actions to perform when processing starts.
},
onFinishProcessing: () {
// Optional: Actions to perform when processing finishes.
},
onError: (error) {
// Optional: Handle errors during processing.
},
);
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SinglePressButton
Constructors
-
SinglePressButton({Key? key, required Widget child, required Future<
void> onPressed(), EdgeInsetsGeometry? padding, EdgeInsetsGeometry? margin, Color? color, Color? disabledColor, double borderRadius = 8.0, TextStyle? textStyle, double? elevation, OutlinedBorder? shape, bool showLoadingIndicator = false, Color? loadingIndicatorColor, VoidCallback? onStartProcessing, VoidCallback? onFinishProcessing, void onError(Object error)?}) -
Creates a SinglePressButton.
const
Properties
- borderRadius → double
-
The border radius of the button.
final
- child → Widget
-
The widget below this widget in the tree.
final
- color → Color?
-
The background color of the button when enabled.
final
- disabledColor → Color?
-
The background color of the button when disabled.
final
- elevation → double?
-
The elevation of the button.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loadingIndicatorColor → Color?
-
The color of the loading indicator.
final
- margin → EdgeInsetsGeometry?
-
The external margin around the button.
final
- onError → void Function(Object error)?
-
Callback invoked when an error occurs during processing.
final
- onFinishProcessing → VoidCallback?
-
Callback invoked when the button finishes processing.
final
-
onPressed
→ Future<
void> Function() -
The callback that is called when the button is tapped.
final
- onStartProcessing → VoidCallback?
-
Callback invoked when the button starts processing.
final
- padding → EdgeInsetsGeometry?
-
The amount of space to surround the child inside the button.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shape → OutlinedBorder?
-
The shape of the button's material.
final
- showLoadingIndicator → bool
-
Whether to show a loading indicator while processing.
final
- textStyle → TextStyle?
-
The text style for the button's label.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< SinglePressButton> -
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