prepareExceptionFunction method

(bool Function(Exception exception)?) prepareExceptionFunction(
  1. {ExceptionExplanationModel? exceptionExplanationModel,
  2. BuildContext? context}
)

Prepares a general Exception handling function based on the provided context and exception model.

  • exceptionExplanationModel contains information about the exception for displaying in the alert dialog.
  • context is the current build context.
  • generalFunction is a function to handle exceptions when a specific function is not provided, and context is null. It is only invoked in this case.

Returns a function to handle the general Exception.

Implementation

bool Function(Exception exception)? prepareExceptionFunction({
  ExceptionExplanationModel? exceptionExplanationModel,
  BuildContext? context,
}) {
  if (context == null) {
    return (Exception exception) {
      debugPrint(exception.toString());
      return true;
    };
  }

  return (Exception exception) => showAlertDialog(
        context,
        exceptionExplanationModel?.title ?? "Unknown Error",
        exceptionExplanationModel?.content ?? "An unexpected error occurred.",
        exceptionExplanationModel?.buttonContent ?? "Close",
      );
}