showCustomAlterDialog function

dynamic showCustomAlterDialog(
  1. BuildContext context, {
  2. required String title,
  3. required String message,
  4. Widget? messageWidget,
  5. required String cancel,
  6. required String confirm,
  7. Color cancelColor = const Color(0xff323233),
  8. Color confirmColor = const Color(0xff1989FA),
  9. GestureTapCallback? onCancel,
  10. GestureTapCallback? onConfirm,
  11. bool barrierDismissible = false,
  12. bool showIcon = false,
  13. Widget? iconWidget,
})

Implementation

showCustomAlterDialog(
  BuildContext context, {
  required String title,
  required String message,
  Widget? messageWidget,
  required String cancel,
  required String confirm,
  Color cancelColor = const Color(0xff323233),
  Color confirmColor = const Color(0xff1989FA),
  GestureTapCallback? onCancel,
  GestureTapCallback? onConfirm,
  bool barrierDismissible = false,
  bool showIcon = false,
  Widget? iconWidget,
}) {
  showDialog<void>(
      context: context,
      barrierDismissible: barrierDismissible,
      builder: (BuildContext dialogContext) {
        return WillPopScope(
          child: Material(
            color: Colors.transparent,
            child: Center(
              // ClipRRect 创建圆角矩形 要不然发现下边button不是圆角
              child: ClipRRect(
                borderRadius: BorderRadius.circular(10.0),
                child: Container(
                  color: Colors.white,
                  width: 260.w,
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      SizedBox(height: 20.h),
                      Visibility(
                        visible: showIcon,
                        child: Center(child: iconWidget),
                      ),
                      title.isEmpty
                          ? const SizedBox.shrink()
                          : Text(
                              title,
                              style: TextStyle(color: const Color(0xff323233), fontSize: 17.sp, fontWeight: FontWeight.bold),
                            ),
                      SizedBox(height: 10.h),
                      message.isEmpty
                          ? const SizedBox.shrink()
                          : Container(
                              margin: EdgeInsets.only(left: 15.w, right: 15.w),
                              child: Text(
                                message,
                                style: TextStyle(color: const Color(0xff323233), fontSize: 14.sp, fontWeight: FontWeight.normal),
                              ),
                            ),
                      messageWidget ?? const SizedBox.shrink(),
                      SizedBox(height: 20.h),
                      Container(
                        decoration: const BoxDecoration(
                          border: Border(bottom: BorderSide(color: Color(0xFFE7E8ED), width: 1)),
                        ),
                      ),
                      Row(children: [
                        Visibility(
                          visible: cancel.isNotEmpty,
                          child: Expanded(
                            flex: 1,
                            child: GestureDetector(
                              onTap: () {
                                Navigator.of(context).pop();
                                if (onCancel != null) {
                                  onCancel();
                                }
                              },
                              child: Container(
                                height: 44.h,
                                alignment: Alignment.center,
                                child: Text(
                                  cancel,
                                  style: TextStyle(color: cancelColor, fontSize: 16.sp),
                                ),
                                decoration: const BoxDecoration(
                                  border: Border(right: BorderSide(color: Color(0xFFE7E8ED), width: 0.5)),
                                ),
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          visible: confirm.isNotEmpty,
                          child: Expanded(
                            flex: 1,
                            child: GestureDetector(
                              onTap: () {
                                Navigator.of(context).pop();
                                if (onConfirm != null) {
                                  onConfirm();
                                }
                              },
                              child: Container(
                                height: 44.h,
                                alignment: Alignment.center,
                                child: Text(
                                  confirm,
                                  style: TextStyle(color: confirmColor, fontSize: 16.sp),
                                ),
                                decoration: const BoxDecoration(
                                  border: Border(left: BorderSide(color: Color(0xFFE7E8ED), width: 0.5)),
                                ),
                              ),
                            ),
                          ),
                        ),
                      ])
                    ],
                  ),
                ),
              ),
            ),
          ),
          onWillPop: () async {
            return false;
          },
        );
      });
}