flutter 自定义中间弹窗

// An highlighted block


import 'package:flutter/material.dart';


class ShowGeneralDialogFunction {
  static void showGeneralDialogFunction(
      BuildContext context, {
      //取消回调
        Function? callBack,
        //确认回调
        Function? cancelBack,
        double? width,
        double? height,
        Widget? title,
        Widget? content,
        String? contentTitle,
        String? cancelText,
        String? disableText,
        Color? cancelTextColor,
        Color? disableTextColor,
        bool barrierDismissible = true,
        //按钮数量,可以设置为一个按钮
        int textButton = 2,
      }) {
    showDialog(
        context: context,
        barrierDismissible: barrierDismissible,
        builder: (buildContext) {
          return Material(
            type: MaterialType.transparency,
            child: Scaffold(
              backgroundColor: Colors.transparent,
              body: Center(
                child: Container(
                  width: width ?? 600.rpx,
                  clipBehavior: Clip.antiAlias,
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(24.rpx)),
                  // height: 300.rpx,

                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      title ?? Container(),
                      content ??
                          Container(
                            margin: EdgeInsets.only(
                                top: 40.rpx,
                                bottom: 40.rpx,
                                right: 24.rpx,
                                left: 24.rpx),
                            child: Text(
                              contentTitle ??
                               "contentTitle",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  height: 1.5,
                                  fontSize: 28.rpx,
                                  color: const Color(0xff2E3346),
                                  fontWeight: FontWeight.w400),
                            ),
                          ),
                      textButton == 2
                          ? Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: () {
                              if (cancelBack != null) cancelBack();
                              Navigator.pop(buildContext);
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: width == null ? 300.rpx : width / 2,
                              height: height ?? 100.rpx,
                              decoration: const BoxDecoration(
                                border: Border(
                                    top: BorderSide(
                                      width: 0.5, //宽度
                                      color: Color(0xffEEEEEE), //边框颜色
                                    )),
                              ),
                              child: Text(
                                cancelText ??
                                  "cancelText",
                                style: TextStyle(
                                    color: cancelTextColor ??
                                        const Color(0xffC8CCD7),
                                    fontSize: 36.rpx,
                                    fontWeight: FontWeight.w500),
                              ),
                            ),
                          ),
                          GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: () {
                              if (callBack != null) callBack();
                              Navigator.pop(buildContext);
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: width == null ? 300.rpx : width / 2,
                              height: height ?? 100.rpx,
                              decoration: const BoxDecoration(
                                border: Border(
                                    left: BorderSide(
                                      width: 0.5, //宽度
                                      color: Color(0xffEEEEEE), //边框颜色
                                    ),
                                    top: BorderSide(
                                      width: 0.5, //宽度
                                      color: Color(0xffEEEEEE), //边框颜色
                                    )),
                              ),
                              child: Text(
                                disableText ??
                                    "disableText",
                                style: TextStyle(
                                    fontSize: 36.rpx,
                                    letterSpacing: -2.rpx,
                                    color: disableTextColor ??
                                        const Color(0xff1A71FF),
                                    fontWeight: FontWeight.w500),
                              ),
                            ),
                          )
                        ],
                      )
                          : Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: () {
                              if (callBack != null) callBack();
                              Navigator.pop(buildContext);
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: width ?? 600.rpx,
                              height: height ?? 100.rpx,
                              decoration: const BoxDecoration(
                                border: Border(
                                    top: BorderSide(
                                      width: 0.5, //宽度
                                      color: Color(0xffEEEEEE), //边框颜色
                                    )),
                              ),
                              child: Text(
                                disableText ??
                                 "disableText",
                                style: TextStyle(
                                    fontSize: 36.rpx,
                                    letterSpacing: -2.rpx,
                                    color: disableTextColor ??
                                        const Color(0xffE72B00),
                                    fontWeight: FontWeight.w500),
                              ),
                            ),
                          )
                        ],
                      )
                    ],
                  ),
                ),
              ),
            ),
          );
        });
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值