feat: integrate agent edit profile screen as an embedded tab in profile settings and restrict agent connection actions to non-agent users

This commit is contained in:
pradeepkumar
2026-04-30 11:31:59 +05:30
parent a1e3fcdb92
commit 004e3caa6e
3 changed files with 47 additions and 24 deletions

View File

@@ -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<ProfileSettingsScreen> {
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<ProfileSettingsScreen> {
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<ProfileSettingsScreen> {
}
}
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<ProfileSettingsScreen> {
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<ProfileSettingsScreen> {
);
}
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(