handleAction method

Future<void> handleAction(
  1. Future<void> function(), {
  2. dynamic onError(
    1. dynamic error
    )?,
  3. String message = '',
  4. bool skipBusyState = false,
})

Perform a future action, catching any exceptions which may occur. This also sets a isBusy flag while the action is being performed.

Implementation

Future<void> handleAction(
  Future<void> Function() function, {
  Function(dynamic error)? onError,
  String message = '',
  bool skipBusyState = false,
}) async {
  currentException = null;
  if (!skipBusyState) {
    isBusy = true;
  }

  try {
    await function();
  } catch (ex) {
    if (onError != null) {
      onError(ex);
    }

    currentException = ex;
    rethrow;
  } finally {
    if (!skipBusyState) {
      isBusy = false;
    }
  }
}