centerDialog static method

void centerDialog({
  1. Widget? title,
  2. String? titleText,
  3. TextStyle? titleStyle,
  4. Widget? content1,
  5. Widget? content2,
  6. Size? size,
  7. Color? color1,
  8. Color? color2,
  9. String? text1,
  10. String? text2,
  11. TextStyle? textStyle1,
  12. TextStyle? textStyle2,
  13. dynamic onPressed1()?,
  14. dynamic onPressed2()?,
  15. bool? isColumnButton,
})

Implementation

static void centerDialog({
  //如果title为空,以下两个组件失效
  Widget? title,
  String? titleText,
  TextStyle? titleStyle,
  Widget? content1,
  Widget? content2,
  Size? size,
  Color? color1,
  Color? color2,
  String? text1,
  String? text2,
  TextStyle? textStyle1,
  TextStyle? textStyle2,
  Function()? onPressed1,
  Function()? onPressed2,
  bool? isColumnButton,
}) {
  titleStyle ??= Get.textTheme.titleLarge;
  title ??= Text(titleText ?? '对话弹窗', style: titleStyle);
  text1 ??= '确定';
  text2 ??= '取消';

  Widget _rowButton() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        XButton(
          color: color1,
          size: size ?? const Size(110, 40),
          text: text1,
          textStyle: textStyle1,
          onTap: () {
            if (onPressed1 != null) {
              Get.back();
              onPressed1();
            } else {
              Get.back();
            }
          },
        ),
        XButton(
          color: color2,
          size: size ?? const Size(110, 40),
          text: text2,
          textStyle: textStyle2,
          onTap: () {
            if (onPressed2 != null) {
              Get.back();
              onPressed2();
            } else {
              Get.back();
            }
          },
        ),
      ],
    );
  }

  Widget _columnButton() {
    return Column(
      children: [
        XButton(
          color: color1,
          size: size ?? const Size(220, 40),
          text: text1,
          textStyle: textStyle1,
          onTap: () {
            if (onPressed1 != null) {
              Get.back();
              onPressed1();
            } else {
              Get.back();
            }
          },
        ),
        XButton(
          color: color2,
          size: size ?? const Size(220, 40),
          text: text2,
          textStyle: textStyle2,
          onTap: () {
            if (onPressed2 != null) {
              Get.back();
              onPressed2();
            } else {
              Get.back();
            }
          },
        ),
      ],
    );
  }

  Get.dialog(
    Dialog(
      child: Material(
        child: Container(
          width: double.infinity,
          padding: const EdgeInsets.fromLTRB(20, 25, 20, 30),
          decoration: BoxDecoration(
            color: Get.theme.dialogTheme.backgroundColor,
            borderRadius: BorderRadius.circular(5),
            border: Border.all(
              color: Colors.grey,
              width: 1,
            ),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              title,
              const Gaph(25),
              content1 ?? Container(),
              (content2 != null)
                  ? Column(children: [const Gaph(25), content2])
                  : Container(),
              const Gaph(25),
              (isColumnButton == true) ? _columnButton() : _rowButton(),
            ],
          ),
        ),
      ),
    ),
  );
}