executeAsyncWithErrorDialog<T> function
Future<T?>
executeAsyncWithErrorDialog<T>(
- BuildContext context, {
- required Future<
T> doProcess(), - void onSuccess(
- T value
- void onError(
- String errMessage
- String? errorAcceptText,
Implementation
Future<T?> executeAsyncWithErrorDialog<T>(
BuildContext context, {
required Future<T> Function() doProcess,
void Function(T value)? onSuccess,
void Function(String errMessage)? onError,
String? errorAcceptText,
}) async {
errorAcceptText ??= strings.acceptButtonText;
T? results;
try {
results = await doProcess();
if (onSuccess != null && results != null) {
onSuccess(results);
}
} catch (err) {
if (context.mounted) {
await showBottomAlertKDialog(
context,
message: err.toString(),
acceptText: errorAcceptText,
);
}
if (onError != null) onError(err.toString());
}
return results;
}