onErrorOrNull method
Executes the provided onError
function if the future completes with
an error.
onError
is the function to be executed when the future completes with
an error.
Example usage:
Future<int?>? nullableFuture = Future.error('An error occurred');
var result = await nullableFuture.onError((error) => print(error));
print(result); // prints: 'An error occurred'
Implementation
Future<void> onErrorOrNull(void Function(dynamic error) onError) {
if (this == null) {
return Future.value();
}
return this!.catchError((error) {
onError(error);
return null;
});
}