AsyncEvent class
Represents an asynchronous event that can be processed by AsyncEventLoaderController.
Each event contains an action that will be executed, along with optional callbacks for success, error, retry, and cancellation scenarios.
Example:
final event = AsyncEvent(
label: 'Fetch User Data',
action: () async {
final user = await api.getUser();
return user;
},
onSuccess: () => print('User fetched successfully'),
onError: (error) => print('Error: $error'),
timeoutDuration: Duration(seconds: 5),
);
Constructors
- AsyncEvent({required Future action(), void onSuccess()?, void onRetry()?, void onError(dynamic error)?, void onCancel()?, int? order, String? label, Duration? timeoutDuration})
-
Creates a new AsyncEvent.
const
- AsyncEvent.empty()
- Creates an empty placeholder event.
Properties
- action → Future Function()
-
The async action to execute.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- label → String?
-
Optional human-readable identifier for the event.
final
- onCancel → void Function()?
-
Callback invoked when the event processing is cancelled.
final
- onError → void Function(dynamic error)?
-
Callback invoked when the action fails after all retries.
final
- onRetry → void Function()?
-
Callback invoked when the event is being retried.
final
- onSuccess → void Function()?
-
Callback invoked when the action completes successfully.
final
- order → int?
-
Optional numeric identifier for ordering events.
final
-
props
→ List<
Object?> -
The list of properties that will be used to determine whether
two instances are equal.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stringify → bool?
-
If set to
true, the toString method will be overridden to output this instance's props.no setterinherited - timeoutDuration → Duration?
-
Optional timeout duration for this event.
final
Methods
-
copyWith(
{Future action()?, void onRetry()?, void onSuccess()?, void onError(dynamic error)?, void onCancel()?, int? order, String? label, Duration? timeoutDuration, bool clearOrder = false, bool clearLabel = false, bool clearTimeoutDuration = false}) → AsyncEvent - Creates a copy of this event with the given fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited