refactor(A1): extract EmailDetailNotifier, drop initState DB coupling #39

Merged
guettlibot merged 1 commits from task/a1-email-detail-notifier into main 2026-05-14 07:49:39 +00:00
guettlibot commented 2026-05-14 07:17:38 +00:00 (Migrated from codeberg.org)

Implements A1 from the improvement plan.

EmailDetailScreen was calling ref.read(emailRepositoryProvider) and
awaiting futures inside initState, tightly coupling the screen to the
repository API. This PR extracts a dedicated EmailDetailNotifier
(AsyncNotifierProvider.autoDispose.family) in di.dart that owns the
load logic and the setFlag(seen: true) side effect. The screen now
watches the provider and renders via detail.when(loading/error/data),
removing all direct repository calls from the widget.

Changes:

  • lib/di.dart: add emailDetailProvider + EmailDetailNotifier; hide
    Drift-generated Email/EmailBody from database.dart to avoid
    ambiguous import with the domain model.
  • lib/ui/screens/email_detail_screen.dart: remove initState override,
    remove _dataFuture field, replace FutureBuilder with ref.watch +
    detail.when, initialize _isFlagged via ref.listen.

Closes #19 (A1)

Implements A1 from the improvement plan. `EmailDetailScreen` was calling `ref.read(emailRepositoryProvider)` and awaiting futures inside `initState`, tightly coupling the screen to the repository API. This PR extracts a dedicated `EmailDetailNotifier` (`AsyncNotifierProvider.autoDispose.family`) in `di.dart` that owns the load logic and the `setFlag(seen: true)` side effect. The screen now watches the provider and renders via `detail.when(loading/error/data)`, removing all direct repository calls from the widget. Changes: - `lib/di.dart`: add `emailDetailProvider` + `EmailDetailNotifier`; hide Drift-generated `Email`/`EmailBody` from `database.dart` to avoid ambiguous import with the domain model. - `lib/ui/screens/email_detail_screen.dart`: remove `initState` override, remove `_dataFuture` field, replace `FutureBuilder` with `ref.watch` + `detail.when`, initialize `_isFlagged` via `ref.listen`. Closes #19 (A1)
Sign in to join this conversation.