b37c46fb9c
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
122 lines
3.6 KiB
Dart
122 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../core/theme/context_tokens.dart';
|
|
|
|
/// Generic dialog wrapper for forms
|
|
class FormDialog extends StatelessWidget {
|
|
final String title;
|
|
final Widget content;
|
|
final String confirmLabel;
|
|
final VoidCallback? onConfirm;
|
|
final bool loading;
|
|
final double width;
|
|
|
|
const FormDialog({
|
|
super.key,
|
|
required this.title,
|
|
required this.content,
|
|
this.confirmLabel = '保存',
|
|
this.onConfirm,
|
|
this.loading = false,
|
|
this.width = 560,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Dialog(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
|
|
child: SizedBox(
|
|
width: width,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Title bar
|
|
Container(
|
|
height: 48,
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
decoration: BoxDecoration(
|
|
color: context.tokens.primary,
|
|
borderRadius: const BorderRadius.only(
|
|
topLeft: Radius.circular(4),
|
|
topRight: Radius.circular(4),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 15,
|
|
fontWeight: FontWeight.w500),
|
|
),
|
|
const Spacer(),
|
|
IconButton(
|
|
icon: const Icon(Icons.close, color: Colors.white, size: 18),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// Content
|
|
Flexible(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(20),
|
|
child: content,
|
|
),
|
|
),
|
|
// Action bar
|
|
const Divider(height: 1),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
OutlinedButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('取消'),
|
|
),
|
|
const SizedBox(width: 12),
|
|
ElevatedButton(
|
|
onPressed: loading ? null : onConfirm,
|
|
child: loading
|
|
? const SizedBox(
|
|
width: 16,
|
|
height: 16,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2, color: Colors.white))
|
|
: Text(confirmLabel),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Show a form dialog and return the result
|
|
Future<T?> showFormDialog<T>({
|
|
required BuildContext context,
|
|
required String title,
|
|
required Widget content,
|
|
String confirmLabel = '保存',
|
|
VoidCallback? onConfirm,
|
|
double width = 560,
|
|
}) {
|
|
return showDialog<T>(
|
|
context: context,
|
|
builder: (_) => FormDialog(
|
|
title: title,
|
|
content: content,
|
|
confirmLabel: confirmLabel,
|
|
onConfirm: onConfirm,
|
|
width: width,
|
|
),
|
|
);
|
|
}
|