refactor: replace FutureProvider caching with Drift stream-based reactivity#238
Open
refactor: replace FutureProvider caching with Drift stream-based reactivity#238
Conversation
PR Preview BuildsBuild Number: 781 Deploy
Android (Firebase App Distribution) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors repository/provider data flow from FutureProvider + manual TTL caching to Drift .watch()-backed StreamProvider reactivity, aiming to make DB the single source of truth and reduce manual provider invalidation across screens.
Changes:
- Replace
getX({refresh})patterns withwatchX()streams +refreshX()imperative methods across Auth/Course/Student repositories. - Update UI providers and screens to consume StreamProviders, simplifying refresh flows and removing most manual invalidation.
- Remove
fetchWithTtlutility (and its tests) and simplify app startup session detection to a direct DB lookup.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| test/utils/fetch_with_ttl_test.dart | Removed tests for fetchWithTtl (utility deleted). |
| lib/utils/fetch_with_ttl.dart | Deleted shared TTL helper in favor of per-repository TTL logic. |
| lib/screens/main/user_providers.dart | Convert user profile to StreamProvider; avatar provider now rebuilds off avatarFilename changes. |
| lib/screens/main/profile/profile_screen.dart | Simplify pull-to-refresh to refreshUser(); remove avatar invalidation after upload. |
| lib/screens/main/profile/profile_providers.dart | Active registration provider now watches DB via stream. |
| lib/screens/main/profile/profile_danger_zone.dart | Remove invalidations that are no longer needed with stream-based providers. |
| lib/screens/main/course_table/course_table_screen.dart | Refresh now calls refreshSemesters() + refreshCourseTable(); remove manual invalidations. |
| lib/screens/main/course_table/course_table_providers.dart | Switch semesters/course table providers to StreamProviders. |
| lib/repositories/auth_repository.dart | Replace getUser() with watchUser() + refreshUser(); active registration now uses .watchSingleOrNull(). |
| lib/repositories/course_repository.dart | Introduce watchSemesters()/refreshSemesters() and watchCourseTable()/refreshCourseTable(); inline TTL for getCourse(). |
| lib/repositories/student_repository.dart | Replace getSemesterRecords() with watchSemesterRecords() + refreshSemesterRecords(). |
| lib/main.dart | Determine initial session via direct DB query instead of getUser(). |
| AGENTS.md | Update architecture documentation to reflect the new stream-based repository pattern. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
976e2da to
01e0510
Compare
Dokploy Preview Deployment
|
…tivity
Replace getX({refresh})/fetchWithTtl pattern with watchX() streams backed
by Drift .watch() queries and refreshX() imperative methods for
pull-to-refresh. Streams emit cached data immediately, background-fetch
when stale, and auto-propagate DB changes — eliminating manual
ref.invalidate() calls across screens.
01e0510 to
9723250
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #220
Summary
getX({refresh})/fetchWithTtlpattern withwatchX()streams backed by Drift.watch()queries andrefreshX()imperative methods for pull-to-refreshref.invalidate()calls across screensuserAvatarProviderwatchesavatarFilenamevia.selectso background profile refreshes automatically update the avatarfetchWithTtlutility and its tests (each method now has its own hard-coded TTLconst)main.dartstartup to a direct DB query instead ofgetUser()Future tasks
connectivityProviderfor offline banners (tracked in AGENTS.md)Test plan