---
phase: 08-task-delete
plan: 02
subsystem: ui
tags: [flutter, riverpod, drift, material3, l10n]

# Dependency graph
requires:
  - phase: 08-task-delete plan 01
    provides: softDeleteTask and getCompletionCount on TasksDao, isActive column migration

provides:
  - smartDeleteTask on TaskActions provider (hard delete if 0 completions, soft delete otherwise)
  - Red delete button in task edit form with Material 3 error color
  - Confirmation AlertDialog using existing German l10n strings
  - Full delete flow: button -> dialog -> smart delete -> navigate back

affects: [task-form, task-providers, any future task management UI]

# Tech tracking
tech-stack:
  added: []
  patterns:
    - Smart delete pattern: check completion count to decide hard vs soft delete
    - Delete confirmation dialog matching room delete pattern with error-colored FilledButton

key-files:
  created: []
  modified:
    - lib/features/tasks/presentation/task_providers.dart
    - lib/features/tasks/presentation/task_form_screen.dart

key-decisions:
  - "smartDeleteTask kept separate from deleteTask to preserve existing hard-delete path for cascade/other uses"
  - "Delete button placed after history section with divider, visible only in edit mode"

patterns-established:
  - "Delete confirmation pattern: showDialog<bool> returning true/false, error-colored FilledButton for confirm"
  - "Smart delete pattern: getCompletionCount -> conditional hard/soft delete invisible to user"

requirements-completed: [DEL-01, DEL-04]

# Metrics
duration: 2min
completed: 2026-03-18
---

# Phase 8 Plan 02: Task Delete UI Summary

**Red delete button with confirmation dialog in task edit form: hard-deletes unused tasks, soft-deletes tasks with completion history**

## Performance

- **Duration:** 2 min
- **Started:** 2026-03-18T19:59:37Z
- **Completed:** 2026-03-18T20:02:05Z
- **Tasks:** 2
- **Files modified:** 2

## Accomplishments

- Added `smartDeleteTask` to `TaskActions` Riverpod notifier — checks completion count and routes to DAO `deleteTask` (hard) or `softDeleteTask` (soft)
- Added red `FilledButton.icon` with error colorScheme at bottom of task edit form, separated from history section by a `Divider`
- Added `_onDelete` confirmation dialog using existing `taskDeleteConfirmTitle`, `taskDeleteConfirmMessage`, `taskDeleteConfirmAction`, and `cancel` l10n strings
- All 144 tests pass, `dart analyze --fatal-infos` clean

## Task Commits

Each task was committed atomically:

1. **Task 1: Add smartDeleteTask to TaskActions provider** - `1b1b981` (feat)
2. **Task 2: Add delete button and confirmation dialog to TaskFormScreen** - `6133c97` (feat)

**Plan metadata:** _(docs commit follows)_

## Files Created/Modified

- `lib/features/tasks/presentation/task_providers.dart` - Added `smartDeleteTask` method to `TaskActions` class
- `lib/features/tasks/presentation/task_providers.g.dart` - Regenerated by build_runner (no functional changes)
- `lib/features/tasks/presentation/task_form_screen.dart` - Added delete button in edit mode and `_onDelete` async method

## Decisions Made

- `smartDeleteTask` kept separate from `deleteTask` to preserve the existing hard-delete path used for room cascade deletes and any other callers
- Delete button placed after history ListTile, inside the `if (widget.isEditing)` block, so it never appears in create mode

## Deviations from Plan

None - plan executed exactly as written.

## Issues Encountered

None.

## User Setup Required

None - no external service configuration required.

## Next Phase Readiness

- Complete delete flow is working: task edit form -> red delete button -> confirmation dialog -> smart delete -> pop back to room task list
- Soft-deleted tasks (isActive=false) are already filtered from all views (implemented in Plan 01)
- Phase 08-task-delete is fully complete

---
*Phase: 08-task-delete*
*Completed: 2026-03-18*

## Self-Check: PASSED

- FOUND: lib/features/tasks/presentation/task_providers.dart
- FOUND: lib/features/tasks/presentation/task_form_screen.dart
- FOUND: .planning/phases/08-task-delete/08-02-SUMMARY.md
- FOUND: commit 1b1b981 (smartDeleteTask)
- FOUND: commit 6133c97 (delete button and dialog)
- FOUND: smartDeleteTask in task_providers.dart
- FOUND: taskDeleteConfirmTitle in task_form_screen.dart
