handleEvent method
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();
}
}