result method

Future<T> result({
  1. void onSuccess(
    1. T data
    )?,
  2. void onError(
    1. Object error
    )?,
})

Executes onSuccess if the future completes successfully, and onError if it fails.

Implementation

Future<T> result({
  void Function(T data)? onSuccess,
  void Function(Object error)? onError,
}) async {
  try {
    final data = await this;
    onSuccess?.call(data);
    return data;
  } catch (e) {
    onError?.call(e);
    rethrow;
  }
}