executeAsync method

Future<void> executeAsync(
  1. Future<T> operation(), {
  2. String? successMessage,
  3. bool emitLoadingState = true,
})

Implementation

Future<void> executeAsync(
  Future<T> Function() operation, {
  String? successMessage,
  bool emitLoadingState = true,
}) async {
  if (emitLoadingState) {
    setLoading();
  }
  try {
    final data = await operation();
    setSuccess(data);
  } catch (e) {
    setError(e.toString());
  }
}