showSnackBarIfError static method

void showSnackBarIfError(
  1. BuildContext context,
  2. CustomError customError, {
  3. Color? backgroundColor,
  4. SnackBarBehavior? behavior,
})

Shows a SnackBar if an error exists in the customError object.

This method displays a SnackBar with the error message from the customError object. You can provide custom backgroundColor and behavior for the SnackBar.

Implementation

static void showSnackBarIfError(BuildContext context, CustomError customError,
    {Color? backgroundColor, SnackBarBehavior? behavior}) {
  if (customError.hasAnError()) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(customError.getError()),
        behavior: behavior ?? SnackBarBehavior.fixed,
        backgroundColor: backgroundColor ?? Colors.black,
      ),
    );
  }
}