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.