showCustomSnackBar method

void showCustomSnackBar(
  1. BuildContext context,
  2. ProKitSnackBar snackBar
)

Displays the custom SnackBar in a dialog at the specified position.

This function creates a dialog that displays the SnackBar based on the given ProKitSnackBarPosition and the provided parameters.

Implementation

void showCustomSnackBar(BuildContext context, ProKitSnackBar snackBar) {
  showDialog(
    context: context,
    barrierColor: Colors.transparent,
    builder: (context) {
      /// Retrieves the alignment for the SnackBar's position.
      final Alignment alignment = snackBar._getAlignmentForPosition(
        snackBar.proKitSnackBarPosition ??
            ProKitSnackBarPosition.bottomCenter,
      );

      /// Adjusts the padding based on the position.
      EdgeInsets padding;
      if (alignment == Alignment.topCenter ||
          alignment == Alignment.topLeft ||
          alignment == Alignment.topRight) {
        padding = EdgeInsets.only(
            top: 15,
            left: alignment == Alignment.topLeft ? 10 : 0,
            right: alignment == Alignment.topRight ? 10 : 0);
      } else if (alignment == Alignment.bottomCenter ||
          alignment == Alignment.bottomLeft ||
          alignment == Alignment.bottomRight) {
        padding = EdgeInsets.only(
            bottom: 15,
            left: alignment == Alignment.bottomLeft ? 10 : 0,
            right: alignment == Alignment.bottomRight ? 10 : 0);
      } else if (alignment == Alignment.centerLeft) {
        padding = const EdgeInsets.only(left: 15);
      } else if (alignment == Alignment.centerRight) {
        padding = const EdgeInsets.only(right: 15);
      } else {
        padding =
            const EdgeInsets.all(15); // Default padding for center alignment
      }

      /// Displays the SnackBar as a dialog with proper alignment and padding.
      return Scaffold(
        backgroundColor: Colors.transparent,
        body: Padding(
          padding: padding,
          child: Align(
            alignment: snackBar._getAlignmentForPosition(
                snackBar.proKitSnackBarPosition ??
                    ProKitSnackBarPosition.bottomCenter),
            child: snackBar,
          ),
        ),
      );
    },
  );
}