From 004e3caa6ef2285b8a3ac08779f9001dd8f423e0 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Thu, 30 Apr 2026 11:31:59 +0530 Subject: [PATCH] feat: integrate agent edit profile screen as an embedded tab in profile settings and restrict agent connection actions to non-agent users --- .../screens/agent_detail_screen.dart | 23 ++++++----- .../screens/agent_edit_profile_screen.dart | 10 ++++- .../screens/profile_settings_screen.dart | 38 ++++++++++++------- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/lib/features/agents/presentation/screens/agent_detail_screen.dart b/lib/features/agents/presentation/screens/agent_detail_screen.dart index dc2444d..bc3b937 100644 --- a/lib/features/agents/presentation/screens/agent_detail_screen.dart +++ b/lib/features/agents/presentation/screens/agent_detail_screen.dart @@ -257,6 +257,9 @@ class _AgentDetailScreenState extends ConsumerState { final agent = state.agent!; final isAvailable = agent.isAvailable; final connState = state.connectionState; + // Hide the Connect/Pending/Unlink button when the viewer is an AGENT — + // the platform does not support agent-to-agent connections. + final viewerIsAgent = ref.watch(authProvider).user?.role == 'AGENT'; return Padding( padding: const EdgeInsets.symmetric(horizontal: 38), @@ -302,18 +305,20 @@ class _AgentDetailScreenState extends ConsumerState { ), ), const Spacer(), - // Connect/Pending/Unlink button - _buildConnectButton( - connState, - isAvailable, - () => _handleConnect(state), - ), - const SizedBox(width: 4), + // Connect/Pending/Unlink button — hidden for agent viewers + if (!viewerIsAgent) ...[ + _buildConnectButton( + connState, + isAvailable, + () => _handleConnect(state), + ), + const SizedBox(width: 4), + ], ], ), ), - // Start Message button when connected - if (connState == 'accepted') ...[ + // Start Message button when connected (only for non-agent viewers) + if (!viewerIsAgent && connState == 'accepted') ...[ const SizedBox(height: 12), _buildStartMessageButton(agent), ], diff --git a/lib/features/agents/presentation/screens/agent_edit_profile_screen.dart b/lib/features/agents/presentation/screens/agent_edit_profile_screen.dart index 6cae9ab..2f2efda 100644 --- a/lib/features/agents/presentation/screens/agent_edit_profile_screen.dart +++ b/lib/features/agents/presentation/screens/agent_edit_profile_screen.dart @@ -71,7 +71,11 @@ class _EditProfileData { // --------------------------------------------------------------------------- class AgentEditProfileScreen extends ConsumerStatefulWidget { - const AgentEditProfileScreen({super.key}); + /// When true, omits the in-screen back button + title row so this widget can + /// be embedded inside another shell (e.g. a tab in ProfileSettingsScreen). + final bool embedded; + + const AgentEditProfileScreen({super.key, this.embedded = false}); @override ConsumerState createState() => @@ -433,6 +437,10 @@ class _AgentEditProfileScreenState Widget build(BuildContext context) { final asyncData = ref.watch(_editProfileDataProvider); + if (widget.embedded) { + return _buildBody(asyncData); + } + return Column( children: [ // Header with back button diff --git a/lib/features/profile/presentation/screens/profile_settings_screen.dart b/lib/features/profile/presentation/screens/profile_settings_screen.dart index ce94f8e..119d9bf 100644 --- a/lib/features/profile/presentation/screens/profile_settings_screen.dart +++ b/lib/features/profile/presentation/screens/profile_settings_screen.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:real_estate_mobile/core/constants/app_colors.dart'; +import 'package:real_estate_mobile/features/agents/presentation/screens/agent_edit_profile_screen.dart'; import 'package:real_estate_mobile/features/profile/presentation/providers/profile_provider.dart'; import 'package:real_estate_mobile/features/profile/presentation/widgets/profile_settings_tab.dart'; import 'package:real_estate_mobile/features/profile/presentation/widgets/change_password_tab.dart'; @@ -18,15 +19,20 @@ class ProfileSettingsScreen extends ConsumerStatefulWidget { } class _ProfileSettingsScreenState extends ConsumerState { - int _selectedTab = 0; + int? _selectedTab; List<_TabItem> _getTabs(bool isAgent) { - final tabs = <_TabItem>[ + final tabs = <_TabItem>[]; + if (isAgent) { + tabs.add( + _TabItem(label: 'Edit Profile', icon: Icons.edit_outlined)); + } + tabs.addAll([ _TabItem(label: 'Profile Settings', icon: Icons.person_outline), _TabItem(label: 'Change Password', icon: Icons.lock_outline), _TabItem(label: 'Notifications', icon: Icons.notifications_none), _TabItem(label: 'Privacy', icon: Icons.shield_outlined), - ]; + ]); if (isAgent) { tabs.add( _TabItem(label: 'Billings & Payments', icon: Icons.payment_outlined)); @@ -67,20 +73,24 @@ class _ProfileSettingsScreenState extends ConsumerState { final tabs = _getTabs(profileState.isAgent); final totalTabs = tabs.length; + // Default tab: Edit Profile (index 0) for agents, Profile Settings (index 0) for users. + final selectedTab = (_selectedTab ?? 0).clamp(0, totalTabs - 1); return Column( children: [ const SizedBox(height: 16), - _buildTabBar(tabs), - _buildProgressBar(totalTabs), - Expanded(child: _buildSelectedTab(tabs)), + _buildTabBar(tabs, selectedTab), + _buildProgressBar(totalTabs, selectedTab), + Expanded(child: _buildSelectedTab(tabs, selectedTab)), ], ); } - Widget _buildSelectedTab(List<_TabItem> tabs) { - final label = tabs[_selectedTab].label; + Widget _buildSelectedTab(List<_TabItem> tabs, int selectedTab) { + final label = tabs[selectedTab].label; switch (label) { + case 'Edit Profile': + return const AgentEditProfileScreen(embedded: true); case 'Profile Settings': return const ProfileSettingsTab(); case 'Change Password': @@ -98,7 +108,7 @@ class _ProfileSettingsScreenState extends ConsumerState { } } - Widget _buildTabBar(List<_TabItem> tabs) { + Widget _buildTabBar(List<_TabItem> tabs, int selectedTab) { return SizedBox( height: 46, child: ListView.separated( @@ -106,13 +116,13 @@ class _ProfileSettingsScreenState extends ConsumerState { padding: const EdgeInsets.symmetric(horizontal: 7), itemCount: tabs.length, separatorBuilder: (_, __) => const SizedBox(width: 6), - itemBuilder: (_, i) => _buildTab(i, tabs[i]), + itemBuilder: (_, i) => _buildTab(i, tabs[i], selectedTab), ), ); } - Widget _buildTab(int index, _TabItem tab) { - final isActive = _selectedTab == index; + Widget _buildTab(int index, _TabItem tab, int selectedTab) { + final isActive = selectedTab == index; return GestureDetector( onTap: () => setState(() => _selectedTab = index), child: Container( @@ -153,8 +163,8 @@ class _ProfileSettingsScreenState extends ConsumerState { ); } - Widget _buildProgressBar(int totalTabs) { - final progress = (_selectedTab + 1) / totalTabs; + Widget _buildProgressBar(int totalTabs, int selectedTab) { + final progress = (selectedTab + 1) / totalTabs; return Padding( padding: const EdgeInsets.symmetric(horizontal: 11, vertical: 16), child: Container(