// 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),
),
),
)
],
)
],
),
),
),
),
);
});
}
}
flutter 自定义中间弹窗
最新推荐文章于 2024-05-05 16:31:03 发布