NullableFutureExtensions<T> extension

Extension on Future<T?>? providing additional null-aware and error handling operations.

This extension adds methods to nullable Future<T?> objects, allowing for more expressive handling of asynchronous operations that could result in null or error states. It includes methods for providing default values, handling errors gracefully, and more nuanced manipulations like executing alternative futures or suppressing errors.

on

Methods

catchErrorOrNull(dynamic onError(Object), {bool test(Object)?}) Future<T?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Attempts to return the future's value; on error, executes an onError function and returns null.
handleNull(T defaultValue) Future<T>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Returns the future's value if not null; otherwise, returns a default value.
ignoreErrors() Future<void>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Suppresses any errors that occur during the future's execution.
onErrorOrNull(void onError(dynamic error)) Future<void>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Executes the provided onError function if the future completes with an error.
onErrorReturn(T value) Future<T?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Attempts to return the future's value; on error, returns a specified value value is the value to be returned when an error occurs.
onErrorReturnNull() Future<T?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Attempts to return the future's value; on error, returns null.
onSuccess(void onSuccess(T value)) Future<void>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Executes the provided onSuccess function if the future completes successfully with a non-null value.
orDefault(T defaultValue) Future<T>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Returns the future's value if not null; otherwise, returns a default value
orElse(Future<T> alternative()) Future<T>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Returns the future's value if not null; otherwise, executes an alternative future.
orNull() Future<T?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Returns the future's value, or null if the future itself is null.
thenOrNull<R>(FutureOr<R?> onValue(T?)) Future<R?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Applies the provided onValue function to the future's value if it is not null.
timeoutWithNull(Duration duration) Future<T?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Returns null if the future does not complete within a specified duration.
transform<R>(R transform(T value)) Future<R?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Applies the provided transform function to the future's value if it is not null.
unwrap() Future<T>?

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Unwraps the future, throwing an error if the future or its value is null.
whenComplete(dynamic action()) Future<T?>

Available on Future<T?>?, provided by the NullableFutureExtensions extension

Executes a specified action when the future completes, regardless of the outcome.