From 6133c977f5c10cd9b1eb17f7e5080fce86e0066d Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Wed, 18 Mar 2026 21:01:53 +0100 Subject: [PATCH] feat(08-02): add delete button and confirmation dialog to TaskFormScreen - Red FilledButton.icon with error color below history section (edit mode only) - _onDelete shows AlertDialog with taskDeleteConfirmTitle/Message l10n strings - Confirm calls smartDeleteTask and pops back to room task list - Cancel dismisses dialog with no action - Button disabled while _isLoading - All 144 tests pass, dart analyze clean --- .../tasks/presentation/task_form_screen.dart | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lib/features/tasks/presentation/task_form_screen.dart b/lib/features/tasks/presentation/task_form_screen.dart index 392bb70..b4b7769 100644 --- a/lib/features/tasks/presentation/task_form_screen.dart +++ b/lib/features/tasks/presentation/task_form_screen.dart @@ -201,6 +201,21 @@ class _TaskFormScreenState extends ConsumerState { taskId: widget.taskId!, ), ), + // DELETE BUTTON + const Divider(), + const SizedBox(height: 8), + SizedBox( + width: double.infinity, + child: FilledButton.icon( + style: FilledButton.styleFrom( + backgroundColor: theme.colorScheme.error, + foregroundColor: theme.colorScheme.onError, + ), + onPressed: _isLoading ? null : _onDelete, + icon: const Icon(Icons.delete_outline), + label: Text(l10n.taskDeleteConfirmAction), + ), + ), ], ], ), @@ -452,6 +467,44 @@ class _TaskFormScreenState extends ConsumerState { } } } + + Future _onDelete() async { + final l10n = AppLocalizations.of(context); + final confirmed = await showDialog( + context: context, + builder: (ctx) => AlertDialog( + title: Text(l10n.taskDeleteConfirmTitle), + content: Text(l10n.taskDeleteConfirmMessage), + actions: [ + TextButton( + onPressed: () => Navigator.pop(ctx, false), + child: Text(l10n.cancel), + ), + FilledButton( + style: FilledButton.styleFrom( + backgroundColor: Theme.of(ctx).colorScheme.error, + ), + onPressed: () => Navigator.pop(ctx, true), + child: Text(l10n.taskDeleteConfirmAction), + ), + ], + ), + ); + + if (confirmed != true || !mounted) return; + + setState(() => _isLoading = true); + try { + await ref.read(taskActionsProvider.notifier).smartDeleteTask(widget.taskId!); + if (mounted) { + context.pop(); + } + } finally { + if (mounted) { + setState(() => _isLoading = false); + } + } + } } /// Unit options for custom frequency input.