FutureDebounceButton<T> class
Future Debounce Button
A button widget that handles asyncronous calls (REST requests etc) and changes its states based on the state of the future it's given.
FutureDebounceButton(
onPressed: ... // required, the Future function to be called
onSuccess: ... // optional, what to do when the future is completed
onAbort: ... // optional, what to do when the user aborts the future
onError: ... // optional, what to do when the future is completed with an error
);
The onSuccess function is called when the onPressed future is completed
with a value. The onError function is called when the onPressed
future is completed with an error.
If the onAbort function is provided, the button becomes "abortable"
(the future could be abandoned and possible result is dropped
instead of being fed to onSuccess handler).
The Future can be aborted by pressing the button again before the
onPressed future is completed.
In this case, the abortChild or abortText is displayed while the
future is running. The onAbort function is called when the user
decides to abort the onPressed future.
To prevent accidental cancellation of a future, the button is debounced
for a period of time specified by debounceDuration before it can be
pressed again. This is only useful if the onAbort is employed.
The timeout parameter is used to specify the maximum duration the
onPressed future can run before it is considered to have failed.
If the timeout is not provided, the onPressed future will run
indefinitely.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- FutureDebounceButton
Constructors
-
FutureDebounceButton({Key? key, bool enabled = true, required Future<
T> onPressed(), void onSuccess(T value)?, dynamic onError(dynamic error, dynamic stackTrace)?, dynamic onAbort()?, void onStateChange(FDBState)?, FDBType buttonType = FDBType.filled, String? actionCallText = 'Go', Widget? actionCallChild, ButtonStyle? actionCallButtonStyle, String? loadingText, Widget? loadingChild, ButtonStyle? loadingButtonStyle, String? abortText = 'Abort', String? abortPressedText = 'Cancelled', Widget? abortChild, Widget? abortPressedChild, ButtonStyle? abortButtonStyle, Duration? abortStateDuration = const Duration(seconds: 1), String? errorText = 'Error', Widget? errorChild, ButtonStyle? errorButtonStyle, Duration? errorStateDuration = const Duration(seconds: 1), String? successText = 'Success!', Widget? successChild, ButtonStyle? successButtonStyle, Duration? successStateDuration = const Duration(seconds: 1), Duration debounceDuration = const Duration(milliseconds: 250), Duration? timeout}) -
const
Properties
- abortButtonStyle → ButtonStyle?
-
The style to be used for the button while the
onPressedfuture is running and user can abort the call.final - abortChild → Widget?
-
The widget to be displayed while the
onPressedfuture is running and user can abort the call.final - abortPressedChild → Widget?
-
The widget to be displayed when the abort action is triggered.
final
- abortPressedText → String?
-
Button text displayed when the abort action is triggered.
Defaults to 'Cancelled'. This label is only used if
abortPressedChildis not provided.final - abortStateDuration → Duration?
-
The duration of the abort state. Defaults to 1 second.
final
- abortText → String?
-
Button text displayed while the
onPressedfuture is running and user can abort the call. Defaults to 'Abort'. This label is only used ifabortChildis not provided.final - actionCallButtonStyle → ButtonStyle?
-
The style to be used for the button before the
onPressedfuture has started.final - actionCallChild → Widget?
-
The widget to be displayed before the
onPressedfuture has started.final - actionCallText → String?
-
Button text displayed before the
onPressedfuture has started. Defaults to 'Go'. This labes is only used ifchildis not provided.final -
The type of button to be displayed. Defaults to
FDBType.elevatedfinal - debounceDuration → Duration
-
The duration of the debounce before the button could be pressed again.
This helps prevent accidental double-taps that cancel the request
right after it fired. This is only useful if the
onAbortis employed. You can also use this to defer the user from being able to abort the call forxamount of time. Defaults to 250 milliseconds.final - enabled → bool
-
dictates is the button is enabled or disabled
final
- errorButtonStyle → ButtonStyle?
-
The style of the button in error state.
final
- errorChild → Widget?
-
The widget to display when the
onPressedfuture has failed.final - errorStateDuration → Duration?
-
The duration of the error state. Defaults to 1 second.
If the duration is set to
null, the error state will be displayed forever. If the duration is set toDuration.zero, the error state will be displayed for one frame.final - errorText → String?
-
Button text displayed when the
onPressedfuture has failed.final - hashCode → int
-
The hash code for this object.
no setterinherited
- isAbortable → bool
-
When isAbortable is
true, the button will activate abort action when pressed again before theonPressedfuture is completed.no setter - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loadingButtonStyle → ButtonStyle?
-
The style to be used for the button while the
onPressedfuture is running and user can not abort the call.final - loadingChild → Widget?
-
The widget to be displayed while the
onPressedfuture is running and user can not abort the call.final - loadingText → String?
-
Button text displayed while the
onPressedfuture is running and user can not abort the call. Defaults to ''. This label is only used ifloadingChildis not provided.final - onAbort → dynamic Function()?
-
What to do if the user decides to abort the
onPressedfuture.final - onError → dynamic Function(dynamic error, dynamic stackTrace)?
-
The
Functionto be called when theonPressedfuture is completed with an error.final -
onPressed
→ Future<
T> Function() -
The
Futurefunction to be called when the button is pressed. This future will be debounced.final - onStateChange → void Function(FDBState)?
-
Triggers every time the button changes state.
final
- onSuccess → void Function(T value)?
-
The
Functionto be called when theonPressedfuture is completed with a value.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- successButtonStyle → ButtonStyle?
-
The style of the button in success state.
final
- successChild → Widget?
-
The widget to display when the
onPressedfuture has failed.final - successStateDuration → Duration?
-
The duration of the success state. Defaults to 1 second.
If the duration is set to
null, the success state will be displayed forever. If the duration is set toDuration.zero, the success state will be displayed for one frame.final - successText → String?
-
Button text displayed when the
onPressedfuture has succeeded.final - timeout → Duration?
-
Future timeout. If the
timeoutis provided, theonPressedfuture will be cancelled after thetimeoutduration. TheonErrorfunction will be called with aTimeoutException. Defaults tonull(no timeout).final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< FutureDebounceButton< T> > -
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
Static Methods
-
defaultErrorButtonStyle(
FDBType buttonType) → ButtonStyle - Returns the default error button style for the given FDBType.
-
defaultSuccessButtonStyle(
FDBType buttonType) → ButtonStyle - Returns the default success button style for the given FDBType.