diff --git a/lib/features/agents/presentation/providers/agent_detail_provider.dart b/lib/features/agents/presentation/providers/agent_detail_provider.dart index 5fceabd..ce8166f 100644 --- a/lib/features/agents/presentation/providers/agent_detail_provider.dart +++ b/lib/features/agents/presentation/providers/agent_detail_provider.dart @@ -388,6 +388,7 @@ class AgentDetailNotifier extends StateNotifier { _repo.getFieldValues(agentId), _repo.getTestimonials(agentId), ]); + if (!mounted) return; state = state.copyWith( agent: results[0] as AgentProfile, fieldValues: results[1] as List, @@ -395,6 +396,7 @@ class AgentDetailNotifier extends StateNotifier { isLoading: false, ); } catch (e) { + if (!mounted) return; state = state.copyWith(isLoading: false, error: e.toString()); } } @@ -406,6 +408,7 @@ class AgentDetailNotifier extends StateNotifier { _repo.getFieldValues(agentId), _repo.getTestimonials(agentId), ]); + if (!mounted) return; state = state.copyWith( agent: results[0] as AgentProfile, fieldValues: results[1] as List, @@ -419,12 +422,14 @@ class AgentDetailNotifier extends StateNotifier { Future loadConnectionStatus() async { final status = await _repo.getConnectionStatus(agentId); + if (!mounted) return; state = state.copyWith(connectionStatus: status); } Future connect({String? message}) async { final success = await _repo.createConnectionRequest(agentId, message: message); + if (!mounted) return success; if (success) { state = state.copyWith( connectionStatus: {'status': 'PENDING'}, @@ -444,6 +449,7 @@ class AgentDetailNotifier extends StateNotifier { final requestId = state.connectionRequestId; if (requestId == null) return false; final success = await _repo.cancelConnectionRequest(requestId); + if (!mounted) return success; if (success) { state = state.copyWith(clearConnection: true); }