完善自主作业下发、暂停恢复和轨迹保留
This commit is contained in:
@@ -13,9 +13,11 @@ Future<bool?> showWorkConfirmDialog(
|
||||
required List<String> checks,
|
||||
required String confirmLabel,
|
||||
bool danger = false,
|
||||
Future<String?> Function()? onConfirm,
|
||||
}) {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: onConfirm == null,
|
||||
barrierColor: const Color(0x8C0B1B2B),
|
||||
builder: (dialogContext) => _WorkConfirmDialog(
|
||||
title: title,
|
||||
@@ -23,17 +25,19 @@ Future<bool?> showWorkConfirmDialog(
|
||||
checks: checks,
|
||||
confirmLabel: confirmLabel,
|
||||
danger: danger,
|
||||
onConfirm: onConfirm,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _WorkConfirmDialog extends StatelessWidget {
|
||||
class _WorkConfirmDialog extends StatefulWidget {
|
||||
const _WorkConfirmDialog({
|
||||
required this.title,
|
||||
required this.desc,
|
||||
required this.checks,
|
||||
required this.confirmLabel,
|
||||
required this.danger,
|
||||
required this.onConfirm,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -41,6 +45,44 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
final List<String> checks;
|
||||
final String confirmLabel;
|
||||
final bool danger;
|
||||
final Future<String?> Function()? onConfirm;
|
||||
|
||||
@override
|
||||
State<_WorkConfirmDialog> createState() => _WorkConfirmDialogState();
|
||||
}
|
||||
|
||||
class _WorkConfirmDialogState extends State<_WorkConfirmDialog> {
|
||||
bool _submitting = false;
|
||||
String? _error;
|
||||
|
||||
Future<void> _confirm() async {
|
||||
if (_submitting) return;
|
||||
final action = widget.onConfirm;
|
||||
if (action == null) {
|
||||
Navigator.of(context).pop(true);
|
||||
return;
|
||||
}
|
||||
final l10n = AppLocalizations.of(context);
|
||||
setState(() {
|
||||
_submitting = true;
|
||||
_error = null;
|
||||
});
|
||||
String? error;
|
||||
try {
|
||||
error = await action();
|
||||
} catch (_) {
|
||||
error = l10n.translate('autonomous_work.dispatch_mode_failed');
|
||||
}
|
||||
if (!mounted || ModalRoute.of(context)?.isCurrent != true) return;
|
||||
if (error == null) {
|
||||
Navigator.of(context).pop(true);
|
||||
} else {
|
||||
setState(() {
|
||||
_submitting = false;
|
||||
_error = error;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static const Color _navy = Color(0xFF1A2B4A);
|
||||
static const Color _gray2 = Color(0xFF5C6B84);
|
||||
@@ -54,7 +96,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final accent = danger ? _danger : _blue;
|
||||
final accent = widget.danger ? _danger : _blue;
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 80, vertical: 24),
|
||||
@@ -82,7 +124,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
widget.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w800,
|
||||
@@ -91,7 +133,9 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => Navigator.of(context).pop(false),
|
||||
onTap: _submitting
|
||||
? null
|
||||
: () => Navigator.of(context).pop(false),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Container(
|
||||
width: 32,
|
||||
@@ -117,7 +161,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
desc,
|
||||
widget.desc,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
height: 1.6,
|
||||
@@ -125,19 +169,23 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
for (final check in checks) ...[
|
||||
for (final check in widget.checks) ...[
|
||||
_checkRow(check, l10n),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
l10n.translate('autonomous_work.confirmation_demo_note'),
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.6,
|
||||
color: Color(0xFFA8B3C5),
|
||||
if (widget.checks.isNotEmpty) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
l10n.translate('autonomous_work.confirmation_demo_note'),
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.6,
|
||||
color: Color(0xFFA8B3C5),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_error case final error?)
|
||||
Text(error, style: const TextStyle(color: _danger)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -149,16 +197,20 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
Expanded(
|
||||
child: _button(
|
||||
label: l10n.translate('common.back'),
|
||||
onTap: () => Navigator.of(context).pop(false),
|
||||
onTap: _submitting
|
||||
? null
|
||||
: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _button(
|
||||
label: confirmLabel,
|
||||
label: _submitting
|
||||
? l10n.translate('autonomous_work.dispatch_mode_sending')
|
||||
: widget.confirmLabel,
|
||||
filled: true,
|
||||
color: accent,
|
||||
onTap: () => Navigator.of(context).pop(true),
|
||||
onTap: _submitting ? null : _confirm,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -208,7 +260,7 @@ class _WorkConfirmDialog extends StatelessWidget {
|
||||
|
||||
Widget _button({
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
required VoidCallback? onTap,
|
||||
bool filled = false,
|
||||
Color color = _blue,
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user