successOrCancel static method
Implementation
static Future successOrCancel({
required BuildContext context,
String? title, // 标题
String? content, // 内容
String? confirm, // 确认按钮
String? cancel, // 取消按钮
bool? barrierDismissible,
Function()? onConfirm, // 确认按钮回调
Function()? onCancel, // 取消按钮回调
}) async {
return await showDialog(
context: context,
barrierDismissible: barrierDismissible ?? true,
builder: (BuildContext context) {
return Dialog(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Container(
padding: EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(
height: 16,
),
// 标题
if (title != null)
Padding(
padding: const EdgeInsets.only(bottom: 24),
child: Text(
title,
softWrap: true,
maxLines: 10,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 20),
)),
if (content != null)
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 24),
child: Text(
content,
softWrap: true,
maxLines: 10,
textAlign: TextAlign.left,
style: const TextStyle(fontSize: 15),
)),
Row(
children: [
Expanded(
child: SizedBox(
height: 50,
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
if (onCancel != null) onCancel();
},
child: Text(
cancel ?? '取消',
style: TextStyle(color: Colors.black),
),
style: ButtonStyle(
backgroundColor:
WidgetStateProperty.all(Colors.white)),
),
)),
SizedBox(
width: 16,
),
Expanded(
child: SizedBox(
height: 50,
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
if (onConfirm != null) onConfirm();
},
child: Text('确认')))),
],
),
SizedBox(
height: 16,
),
],
),
),
);
},
);
}