Date: May 31, 2026
Architect: Principal Mobile & Backend Architect
This document preserves the context, logic, and solutions implemented during the systematic fix execution of the non-marketplace items from the FULL_PROJECT_AUDIT_REPORT.md.
- Goal: Override Audit Items 1.1 and 1.2. Completely remove the Treat and Undo features.
- Files Modified:
- matching_screen.dart
- Actions Taken:
- Removed the bone icon (
🦴) Treat button and its stubbed snackbar handler from the swipe screen dock. - Removed the replay icon (
↺) Undo button and its stubbed snackbar handler from the swipe screen dock. - Removed all companion margins and layout spacing associated with these buttons.
- Removed the bone icon (
- Goal: Implement the admin read policy for the
medical-documentsstorage bucket (Audit Item 4.8). - Files Modified / Created:
- 20260531_audit_fixes.sql [NEW]
- Fix details:
- Added a
medical-documentsbucket admin read policy. - Wrapped the authentication checks in a subselect
(select public.is_admin())to force the Postgres optimizer to cache the plan and prevent severe database jank.
CREATE POLICY "medical-documents: admin read" ON storage.objects FOR SELECT TO authenticated USING ( bucket_id = 'medical-documents' AND (select public.is_admin()) );
- Added a
- Goal: Eliminate duplicate listeners and build-phase mutations inside
CareNotifier(Audit Item 2.2). - Files Modified:
- care_controller.dart
- Fix details:
- Replaced the unsafe
ref.listen<DailyRoutineState>(careDashboardProvider, ...)insidebuild()withref.watch(careDashboardProvider). - Deferred the state synchronization side effects to run inside
Future.microtaskto guarantee it does not trigger Riverpod's "mutating state during build" exceptions.
@override CareState build() { final petId = arg; final dashboard = ref.watch(careDashboardProvider); Future.microtask(() { if (ref.mounted) { _onDashboardChange(dashboard); } }); // ... }
- Replaced the unsafe
- Goal: Resolve deep-link race condition for the pet edit route (Audit Item 3.5).
- Files Modified:
- router.dart
- Fix details:
- Replaced the inline
ref.read(petListProvider).valuelookup inside GoRouter's builder block with a dynamicConsumerthat actively watches (ref.watch) thepetListProvider. - Handled the loading, error, and data states appropriately using
AsyncValue.whento prevent the false-positive "Pet not found" screen during cold-start deep-links.
- Replaced the inline
- Goal: Add limits to unbounded streams/queries (Audit Item 3.1 & 3.3) and optimize follows checks (Audit Item 3.6).
- Files Modified:
- matching_supabase_data_source.dart
- health_repository.dart
- health_vault_controller.dart
- social_repository.dart
- Fix details:
- Added
.limit(100)boundaries tofetchMatchesForPetandfetchLogsForPetqueries. - Added
.limit(100)to themedical_vaultrealtime stream inHealthVaultController. - Refactored
isFollowingto select onlyfollower_pet_idinstead of performing a full wildcard column select (.select()).
- Added
- Goal: Convert memory-heavy list instantiations to lazy virtualization (Audit Item 4.2).
- Files Modified:
- care_screen.dart
- matches_inbox_screen.dart
- Fix details:
- Converted the main layout container of
care_screen.dartto aListView.builder. - Refactored the matches inbox screen to build a composite item representation, fully virtualizing the inbox messages list using
ListView.builder. - Added a
mountedguard prior to performing context layout calculations (context.size) insidecare_screen.dart's_scrollToToday().
- Converted the main layout container of
- Goal: Wire up overflow menus, hide stubbed icons/actions (Audit Items 1.7, 1.4, 1.3).
- Files Modified:
- post_detail_screen.dart
- social_screen.dart
- manage_pets_screen.dart
- Actions Taken:
- Renamed
_PostOptionsSheettoPostOptionsSheet(made public) inpost_detail_screen.dart. - Wired up the three-dot button in feed cards (
social_screen.dart) to show the sheet. - Removed the stubbed search icon from the feed header actions.
- Removed the unimplemented co-carer "Share access" option from the pet actions popup menu in
manage_pets_screen.dart.
- Renamed
- Goal: Replace silent error swallowing with minimal retry blocks (Audit Item 3.4) and optimize MediaQuery subscriptions (Audit Item 4.3).
- Files Modified:
- nutrition_screen.dart
- social_screen.dart
- social_profile_screen.dart
- pet_switcher_sheet.dart
- pet_profile_screen.dart
- onboarding_screen.dart
- Fix details:
- Implemented elegant error and retry indicators (
ref.invalidate/refresh) inside the five swallowed error scenarios (Weight list, Stories, Achievements tab, Switcher sheet, and Quests card). - Optimized
MediaQuery.of(context)subscriptions inonboarding_screen.dartandnutrition_screen.dartto useMediaQuery.sizeOf(context)andMediaQuery.viewInsetsOf(context)to prevent unnecessary widget rebuilds.
- Implemented elegant error and retry indicators (
- Goal: Setup global crash catching (Audit Item 4.5).
- Files Modified:
- main.dart
- Fix details:
- Registered unified error hooks for synchronous Widget build errors and asynchronous exceptions:
FlutterError.onError = (details) { FlutterError.presentError(details); }; PlatformDispatcher.instance.onError = (error, stack) { debugPrint('Unhandled async error: $error\n$stack'); return true; };
- Goal: Ensure all modal bottom sheets/popups appear on top of the persistent bottom navigation bar.
- Files Modified:
- create_post_screen.dart
- post_detail_screen.dart
- social_screen.dart
- manage_pets_screen.dart
- nutrition_screen.dart
- Fix details:
- Added
useRootNavigator: trueto the remainingshowModalBottomSheetcalls in the application context so that the modals are pushed on the root navigator instead of the GoRouter nested shell route navigator. This resolves the issue where the bottom navigation bar overlaps or obscures bottom sheets.
- Added