check method

dynamic check(
  1. ResultResp resp, {
  2. bool showDialogError = true,
  3. bool checkSession = true,
  4. dynamic onSuccess()?,
  5. dynamic onFailure()?,
  6. dynamic actionDialogError()?,
})

Checks the status response resp and performs actions based on the result.

The showDialogError parameter determines whether to show a default modal bottom sheet with an error message. The checkSession parameter determines whether to check for an invalid session and show a specific error message. The onSuccess callback is called if the response is a success. The onFailure callback is called if the response is not a success. The actionDialogError callback is called when the error dialog is pressed.

Example usage:

check(
  ResultResp resp, {
  bool showDialogError = true,
  bool checkSession = true,
  Function()? onSuccess,
  Function()? onFailure,
  Function()? actionDialogError,
}) async {
  // implementation
}

Implementation

check(
  ResultResp resp, {
  bool showDialogError = true,
  bool checkSession = true,
  Function()? onSuccess,
  Function()? onFailure,
  Function()? actionDialogError,
}) async {
  final code = resp.code;
  final message = resp.message;
  if (resp is SuccessResp) {
    onSuccess?.call();
  } else {
    onFailure?.call();
    if (code == codeInvalidSession && checkSession) {
      appNavigator.showDefaultModalBottom(
        isDismissible: false,
        title: 'Session invalid!',
        message:
            'Your session has expired, please re-login with your password',
        buttonTitle: 'Login',
        onPressed: () => appNavigator.pushReplacement(replaceLoginScreen),
      );
    } else {
      if (showDialogError) {
        appNavigator.showDefaultModalBottom(
            message: message, onPressed: actionDialogError);
      }
    }
  }
}