fix: invalidate agentDetailProvider using both profile ID and user ID to prevent stale cache after profile updates

This commit is contained in:
pradeepkumar
2026-04-20 09:30:37 +05:30
parent 0a11d61a6c
commit c006c141f7

View File

@@ -388,9 +388,16 @@ class _AgentEditProfileScreenState
} }
// Invalidate the agent detail provider so the dashboard refetches // Invalidate the agent detail provider so the dashboard refetches
// field values after save (was showing stale cached data). // field values after save. The provider is keyed by agentProfileId
// (NOT userId), so pull it from the profile payload we just loaded.
final agentProfileId = data.profile['id'] as String?;
if (agentProfileId != null && agentProfileId.isNotEmpty) {
ref.invalidate(agentDetailProvider(agentProfileId));
}
// Also invalidate by userId as a fallback (covers any screen that
// may key the provider by userId instead).
final userId = ref.read(authProvider).user?.id; final userId = ref.read(authProvider).user?.id;
if (userId != null) { if (userId != null && userId != agentProfileId) {
ref.invalidate(agentDetailProvider(userId)); ref.invalidate(agentDetailProvider(userId));
} }
ref.invalidate(_editProfileDataProvider); ref.invalidate(_editProfileDataProvider);