onComplete method

Future<T?> onComplete({
  1. required FutureOr<void> onSuccess(
    1. T r
    ),
  2. required FutureOr<void> onError(
    1. Object e,
    2. StackTrace s
    ),
  3. AsyncExtensionErrorLogger? errorLogger,
  4. bool logError = true,
})

Calls onSuccess or onError when this Future completes.

Logs the error using errorLogger or defaultAsyncExtensionErrorLogger if parameter logError is true.

Implementation

Future<T?> onComplete({
  required FutureOr<void> Function(T r) onSuccess,
  required FutureOr<void> Function(Object e, StackTrace s) onError,
  AsyncExtensionErrorLogger? errorLogger,
  bool logError = true,
}) async {
  try {
    var r = await this;
    await onSuccess(r);
    return r;
  } catch (e, s) {
    if (logError) errorLogger.logError(e, s);
    await onError(e, s);
    return null;
  }
}