# Phase 7: Task Sorting - Context

**Gathered:** 2026-03-16
**Status:** Ready for planning

<domain>
## Phase Boundary

Add sort controls to task list screens so users can reorder tasks by name (alphabetical), frequency interval, or effort level. The sort preference persists across app restarts. Requirements: SORT-01, SORT-02, SORT-03.

</domain>

<decisions>
## Implementation Decisions

### Sort control widget
- Dropdown button in the AppBar, right side (trailing actions position)
- When collapsed, shows the current sort name as text (e.g., "A-Z", "Intervall", "Aufwand")
- Expands to show the 3 sort options as a standard dropdown menu

### Sort option labels
- Claude's discretion — pick German labels that fit the app's existing localization style (concise but clear)

### Sort scope
- One global sort preference applies to all task list screens
- Same dropdown appears in both the home screen (CalendarDayList) and per-room (TaskListScreen) AppBars

### Persistence
- Store the sort preference in SharedPreferences (simple key-value for a single enum)
- No database schema change needed
- Persists across app restarts per success criteria

### Default sort
- Claude's discretion — pick the least disruptive default (likely alphabetical to match current CalendarDayList behavior)

### Claude's Discretion
- Sort option label text (German, concise)
- Default sort order (recommend alphabetical for continuity)
- Whether TaskListScreen also gets the dropdown (recommend yes for consistency with global setting, since the success criteria says "task list screens" plural)
- Sort direction (always ascending — A-Z, daily→yearly, low→high — no toggle needed for MVP)
- Dropdown styling (Material 3 DropdownButton or PopupMenuButton variant)
- Sort icon or visual indicator in the dropdown
- How overdue section interacts with sorting (recommend: overdue section stays pinned at top regardless of sort, only day tasks are sorted)

</decisions>

<specifics>
## Specific Ideas

No specific requirements — open to standard approaches that match existing app patterns.

</specifics>

<code_context>
## Existing Code Insights

### Reusable Assets
- `EffortLevel` enum (low/medium/high) with `.index` for ordering — directly usable for effort sort
- `IntervalType` enum with `.index` ordered roughly by frequency (daily=0 through yearly=7) — usable for interval sort
- `FrequencyInterval.presets` list ordered most-frequent to least — reference for sort order
- `Task.name` field — direct alphabetical sort target
- `CalendarDayList` and `TaskListScreen` — the two list widgets that need sort integration
- `AppLocalizations` + `.arb` files — existing German localization pipeline

### Established Patterns
- Manual `StreamProvider.autoDispose` for drift types (riverpod_generator issue) — sort provider follows same pattern
- `calendarDayProvider` watches `selectedDateProvider` — can also watch a sort preference provider
- `tasksInRoomProvider` family provider — can be extended with sort parameter or read global sort
- Feature folder structure: `features/home/`, `features/tasks/` — sort logic may live in a shared location or in each feature

### Integration Points
- `HomeScreen` AppBar — add dropdown to trailing actions
- `TaskListScreen` AppBar — already has edit/delete actions; add dropdown alongside
- `CalendarDao.watchTasksForDate()` — currently sorts alphabetically; needs sort-aware query or in-memory sort
- `TasksDao.watchTasksInRoom()` — currently sorts by nextDueDate; needs sort-aware query or in-memory sort
- `SharedPreferences` — not yet used in the app; needs package addition and provider setup
- `app_de.arb` — add localization strings for sort labels

</code_context>

<deferred>
## Deferred Ideas

None — discussion stayed within phase scope

</deferred>

---

*Phase: 07-task-sorting*
*Context gathered: 2026-03-16*
