showDefault method

void showDefault({
  1. String? title,
  2. Color? titleColor,
  3. double? titleSize,
  4. FontWeight? titleWeight,
  5. String? message,
  6. Color? messageColor,
  7. double? messageSize,
  8. FontWeight? messageWeight,
  9. String? buttonOneText = '',
  10. Color? buttonOneTextColor,
  11. double? buttonOneTextSize,
  12. FontWeight? buttonOneTextWeight,
  13. Color? buttonOneColor,
  14. RadiusPlus? buttonOneRadius,
  15. dynamic buttonOneCallback()?,
  16. String? buttonTwoText = '',
  17. Color? buttonTwoTextColor,
  18. double? buttonTwoTextSize,
  19. FontWeight? buttonTwoTextWeight,
  20. Color? buttonTwoColor,
  21. RadiusPlus? buttonTwoRadius,
  22. dynamic buttonTwoCallback()?,
  23. double? buttonsHeight,
  24. EdgeInsetsGeometry? padding,
  25. Color? barrierColor,
  26. bool barrierDismissible = true,
  27. bool closeKeyboardWhenOpen = true,
  28. RadiusPlus? radius,
  29. BorderPlus? border,
  30. double elevation = 1,
  31. double elementsSpacing = 16,
  32. double? screenHorizontalMargin,
})

Shows default Dialog with some customizations

Implementation

void showDefault({
  // title
  String? title,
  Color? titleColor,
  double? titleSize,
  FontWeight? titleWeight,
  // message
  String? message,
  Color? messageColor,
  double? messageSize,
  FontWeight? messageWeight,
  // button one
  String? buttonOneText = '',
  Color? buttonOneTextColor,
  double? buttonOneTextSize,
  FontWeight? buttonOneTextWeight,
  Color? buttonOneColor,
  RadiusPlus? buttonOneRadius,
  Function()? buttonOneCallback,
  // buttonTwo
  String? buttonTwoText = '',
  Color? buttonTwoTextColor,
  double? buttonTwoTextSize,
  FontWeight? buttonTwoTextWeight,
  Color? buttonTwoColor,
  RadiusPlus? buttonTwoRadius,
  Function()? buttonTwoCallback,
  // others
  double? buttonsHeight,
  EdgeInsetsGeometry? padding,
  Color? barrierColor,
  bool barrierDismissible = true,
  bool closeKeyboardWhenOpen = true,
  RadiusPlus? radius,
  BorderPlus? border,
  double elevation = 1,
  double elementsSpacing = 16,
  double? screenHorizontalMargin,
}) {
  if (closeKeyboardWhenOpen == true) {
    utilsPlus.closeKeyboard();
  }
  showDialog(
    context: navigatorPlus.currentContext!,
    barrierColor: barrierColor,
    barrierDismissible: buttonOneText == null ? true : barrierDismissible,
    builder: (context) {
      Widget? buttonsContent;
      if (buttonOneText!.isNotNullOrEmpty &&
          buttonTwoText!.isNotNullOrEmpty) {
        buttonsContent = Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(
              child: _createButton(
                buttonOneText,
                buttonOneTextColor,
                buttonOneTextSize,
                buttonOneTextWeight,
                buttonsHeight,
                buttonOneColor,
                buttonOneRadius,
                buttonOneCallback,
              ),
            ),
            SizedBox(
              width: elementsSpacing,
            ),
            Expanded(
              child: _createButton(
                buttonTwoText,
                buttonTwoTextColor,
                buttonTwoTextSize,
                buttonTwoTextWeight,
                buttonsHeight,
                buttonTwoColor,
                buttonTwoRadius,
                buttonTwoCallback,
              ),
            )
          ],
        );
      } else if (buttonOneText.isNotNullOrEmpty) {
        buttonsContent = _createButton(
          buttonOneText,
          buttonOneTextColor,
          buttonOneTextSize,
          buttonOneTextWeight,
          buttonsHeight,
          buttonOneColor,
          buttonOneRadius,
          buttonOneCallback,
        );
      } else if (buttonTwoText!.isNotNullOrEmpty) {
        buttonsContent = _createButton(
          buttonTwoText,
          buttonTwoTextColor,
          buttonTwoTextSize,
          buttonTwoTextWeight,
          buttonsHeight,
          buttonTwoColor,
          buttonTwoRadius,
          buttonTwoCallback,
        );
      }

      TextPlus? titleWidget;
      if (title != null) {
        titleWidget = TextPlus(
          title,
          color: titleColor ?? Colors.black,
          fontSize: titleSize ?? 20,
          fontWeight: titleWeight ?? FontWeight.w700,
          textAlign: TextAlign.center,
          textOverflow: TextOverflow.ellipsis,
        );
      }

      TextPlus? messageWidget;
      if (message != null) {
        messageWidget = TextPlus(
          message,
          color: messageColor ?? Colors.grey,
          fontSize: messageSize ?? 16,
          fontWeight: messageWeight ?? FontWeight.normal,
          textAlign: TextAlign.center,
          // textOverflow: TextOverflow.ellipsis,
        );
      }

      var dialogContent = Padding(
        padding: padding ?? EdgeInsets.all(16),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            titleWidget ?? SizedBox.shrink(),
            messageWidget != null
                ? SizedBox(
                    height: elementsSpacing,
                  )
                : SizedBox.shrink(),
            messageWidget ?? SizedBox.shrink(),
            buttonsContent != null
                ? SizedBox(
                    height: elementsSpacing,
                  )
                : SizedBox.shrink(),
            buttonsContent ?? SizedBox.shrink(),
          ],
        ),
      );
      return _createDialog(
        dialogContent,
        elevation,
        radius ?? RadiusPlus.all(20),
        border,
        screenHorizontalMargin,
      );
    },
  );
}