mutateAsync<T> method
Future<void>
mutateAsync<T>({
- required Future<
T> action(), - required void apply(
- T result
- void onError(
- Object error,
- StackTrace stack
- String? label,
Asynchronously executes action, then passes the result to apply inside mutate if successful.
If an error occurs during action, calls onError if provided; otherwise
records the error and rethrows.
Implementation
@protected
Future<void> mutateAsync<T>({
required Future<T> Function() action,
required void Function(T result) apply,
void Function(Object error, StackTrace stack)? onError,
String? label,
}) async {
if (_disposed) return;
T result;
try {
result = await action();
} catch (e, st) {
if (onError != null) {
onError(e, st);
} else {
_onMutationError(e, st, label);
rethrow;
}
return;
}
if (_disposed) return;
try {
mutate(() => apply(result), label: label);
} catch (e, st) {
if (onError != null) {
onError(e, st);
} else {
rethrow;
}
}
}