diff --git a/lib/features/messaging/presentation/providers/messaging_provider.dart b/lib/features/messaging/presentation/providers/messaging_provider.dart index 5db0893..0f3d603 100644 --- a/lib/features/messaging/presentation/providers/messaging_provider.dart +++ b/lib/features/messaging/presentation/providers/messaging_provider.dart @@ -75,7 +75,8 @@ class MessagingNotifier extends StateNotifier { MessagingNotifier(this._repository, this._ref) : super(const MessagingState()) { _initSocketListeners(); - loadUnreadCount(); + // Defer to avoid modifying provider during widget tree build + Future.microtask(() => loadUnreadCount()); } String? get _currentUserId => _ref.read(authProvider).user?.id; @@ -529,6 +530,7 @@ class MessagingNotifier extends StateNotifier { Future markAsRead(String conversationId) async { try { await _repository.markAsRead(conversationId); + if (!mounted) return; final updatedConversations = state.conversations.map((c) { if (c.id == conversationId) { @@ -550,6 +552,7 @@ class MessagingNotifier extends StateNotifier { } void setActiveConversation(String? conversationId) { + if (!mounted) return; if (conversationId == null) { state = state.copyWith(clearActiveConversation: true); } else { @@ -560,7 +563,7 @@ class MessagingNotifier extends StateNotifier { Future loadUnreadCount() async { try { final count = await _repository.getUnreadCount(); - state = state.copyWith(unreadCount: count); + if (mounted) state = state.copyWith(unreadCount: count); } catch (_) {} } diff --git a/lib/features/messaging/presentation/screens/chat_screen.dart b/lib/features/messaging/presentation/screens/chat_screen.dart index 9a57964..3d9ef37 100644 --- a/lib/features/messaging/presentation/screens/chat_screen.dart +++ b/lib/features/messaging/presentation/screens/chat_screen.dart @@ -90,16 +90,12 @@ class _ChatScreenState extends ConsumerState } } - @override - @override - void deactivate() { - // Clear active conversation while ref is still valid (before dispose) - ref.read(messagingProvider.notifier).setActiveConversation(null); - super.deactivate(); - } - @override void dispose() { + // Defer provider modification to avoid "modify during build" error + final notifier = ref.read(messagingProvider.notifier); + Future.microtask(() => notifier.setActiveConversation(null)); + WidgetsBinding.instance.removeObserver(this); _connectionSub?.cancel(); // Stop typing and leave room before disposing diff --git a/lib/features/profile/presentation/widgets/profile_settings_tab.dart b/lib/features/profile/presentation/widgets/profile_settings_tab.dart index 6da3362..2c7a09e 100644 --- a/lib/features/profile/presentation/widgets/profile_settings_tab.dart +++ b/lib/features/profile/presentation/widgets/profile_settings_tab.dart @@ -262,12 +262,14 @@ class _ProfileSettingsTabState extends ConsumerState { const SizedBox(height: 24), ProfileFormField(label: 'Full Name', controller: _fullNameController), - const SizedBox(height: 24), - ProfileFormField( - label: isAgent ? 'Career / Agent Type' : 'Professional Title', - controller: _titleController, - enabled: false, - ), + if (isAgent) ...[ + const SizedBox(height: 24), + ProfileFormField( + label: 'Career / Agent Type', + controller: _titleController, + enabled: false, + ), + ], const SizedBox(height: 24), ProfileFormField( label: 'Email Address', diff --git a/lib/routing/app_router.dart b/lib/routing/app_router.dart index 91be979..662c7d0 100644 --- a/lib/routing/app_router.dart +++ b/lib/routing/app_router.dart @@ -160,7 +160,9 @@ final routerProvider = Provider((ref) { return CustomTransitionPage( key: state.pageKey, child: ChatScreen(conversationId: id), - transitionsBuilder: _fadeTransition, + transitionDuration: const Duration(milliseconds: 250), + reverseTransitionDuration: const Duration(milliseconds: 200), + transitionsBuilder: _slideTransition, ); }, ), @@ -272,6 +274,22 @@ class _HomeRouteWrapper extends ConsumerWidget { } } +/// Slide from right transition for push-style navigation. +Widget _slideTransition( + BuildContext context, + Animation animation, + Animation secondaryAnimation, + Widget child, +) { + return SlideTransition( + position: Tween( + begin: const Offset(1, 0), + end: Offset.zero, + ).animate(CurvedAnimation(parent: animation, curve: Curves.easeOut)), + child: child, + ); +} + /// Smooth fade transition for tab-to-tab navigation. Widget _fadeTransition( BuildContext context,