121 lines
3.6 KiB
Dart
121 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
// 自定义弹窗
|
|
class CustomAlertDialog extends StatelessWidget {
|
|
final String title;
|
|
final String content;
|
|
final VoidCallback onConfirm;
|
|
final VoidCallback? onCancel;
|
|
final String confirmText; // 新增
|
|
final String cancelText;
|
|
final Widget? contentWidget;
|
|
|
|
const CustomAlertDialog({
|
|
super.key,
|
|
required this.title,
|
|
required this.content,
|
|
required this.onConfirm,
|
|
this.onCancel,
|
|
this.confirmText = '确定',
|
|
this.cancelText = '取消',
|
|
this.contentWidget,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
contentPadding: EdgeInsets.zero, // 移除默认内边距
|
|
title: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: const TextStyle(color: Colors.white, fontSize: 20),
|
|
textAlign: TextAlign.center, // 添加文本居中
|
|
),
|
|
if (contentWidget != null) ...[
|
|
const SizedBox(height: 10),
|
|
contentWidget!, // 使用自定义内容
|
|
] else if (content.isNotEmpty) ...[
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
content,
|
|
style: const TextStyle(color: Colors.white54, fontSize: 14),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
content: Container(
|
|
decoration: const BoxDecoration(
|
|
border: Border(
|
|
top: BorderSide(
|
|
color: Color(0xFF2A2C38),
|
|
width: 1,
|
|
),
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
border: Border(
|
|
right: BorderSide(
|
|
color: Color(0xFF2A2C38),
|
|
width: 1,
|
|
),
|
|
),
|
|
),
|
|
child: TextButton(
|
|
onPressed: () {
|
|
if (onCancel != null) {
|
|
onCancel!();
|
|
} else {
|
|
Navigator.of(context).pop();
|
|
}
|
|
},
|
|
style: TextButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
backgroundColor: Colors.transparent,
|
|
),
|
|
child: Text(
|
|
cancelText,
|
|
style:const TextStyle(
|
|
color: Color(0xFF999999),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: TextButton(
|
|
onPressed: onConfirm,
|
|
style: TextButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
backgroundColor: Colors.transparent,
|
|
),
|
|
child: Text(
|
|
confirmText,
|
|
style:const TextStyle(
|
|
color: Color(0xFF7cd3ba),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
backgroundColor: const Color(0xFF1F212E),
|
|
);
|
|
}
|
|
} |