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
This commit is contained in:
@@ -201,6 +201,21 @@ class _TaskFormScreenState extends ConsumerState<TaskFormScreen> {
|
||||
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<TaskFormScreen> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onDelete() async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final confirmed = await showDialog<bool>(
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user