Files
flutter-template/lib/core/widgets/confirm_dialog.dart
T
SkyJourney 61017f1c39 chore: 初始化脚手架 — sunny_mochi 企业级 Flutter 模板
Core 基础设施:Flavor 三包体系、Drift+SQLCipher 加密数据库
7 拦截器 Dio 网络栈、CrashReporter 崩溃日志、Sealed Failure 错误体系
5 色板主题系统、Auth 认证骨架(Clean Architecture)、Dev Panel、Mock Adapter

通过验证:flutter analyze(0 errors)、flutter test(全绿)、staging APK 74.8MB
2026-05-14 12:51:05 +08:00

74 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
/// 通用确认对话框。
///
/// 用法:
/// ```dart
/// final ok = await ConfirmDialog.show(
/// context,
/// title: '删除确认',
/// message: '确定要删除该记录吗?',
/// confirmLabel: '删除',
/// destructive: true,
/// );
/// if (ok == true) { /* do it */ }
/// ```
class ConfirmDialog extends StatelessWidget {
const ConfirmDialog({
super.key,
required this.title,
required this.message,
this.confirmLabel = '确定',
this.cancelLabel = '取消',
this.destructive = false,
});
final String title;
final String message;
final String confirmLabel;
final String cancelLabel;
final bool destructive;
static Future<bool?> show(
BuildContext context, {
required String title,
required String message,
String confirmLabel = '确定',
String cancelLabel = '取消',
bool destructive = false,
}) {
return showDialog<bool>(
context: context,
builder: (_) => ConfirmDialog(
title: title,
message: message,
confirmLabel: confirmLabel,
cancelLabel: cancelLabel,
destructive: destructive,
),
);
}
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return AlertDialog(
title: Text(title),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(cancelLabel),
),
TextButton(
style: destructive
? TextButton.styleFrom(foregroundColor: colorScheme.error)
: null,
onPressed: () => Navigator.of(context).pop(true),
child: Text(confirmLabel),
),
],
);
}
}