handleEvent method

Future<void> handleEvent(
  1. Emitter<State> emit,
  2. Future<void> call(), {
  3. required Future<void> onError(
    1. dynamic error
    ),
  4. required Future<void> onCompleted(),
})

A helper function to handle asynchronous events with error handling and completion callbacks.

emit - The state emitter.

call - The main asynchronous function to execute.

onError - Callback to handle any error that occurs during call.

onCompleted - Callback that runs after call completes, whether it succeeds or fails.

Implementation

Future<void> handleEvent(
  Emitter<State> emit,
  Future<void> Function() call, {
  required Future<void> Function(dynamic error) onError,
  required Future<void> Function() onCompleted,
}) async {
  try {
    await call();
  } catch (error) {
    LoggerUtil.e(error.toString());
    await onError(error);
  } finally {
    await onCompleted();
  }
}