From 130583c98c31c275dfa9feda91bb32f3414de031 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sat, 28 Mar 2026 18:46:40 +0530 Subject: [PATCH] refactor: simplify privacy tab by removing data settings and restricting profile visibility to agents only --- .../presentation/widgets/privacy_tab.dart | 158 +++++------------- 1 file changed, 38 insertions(+), 120 deletions(-) diff --git a/lib/features/profile/presentation/widgets/privacy_tab.dart b/lib/features/profile/presentation/widgets/privacy_tab.dart index 0a6107b..91723ff 100644 --- a/lib/features/profile/presentation/widgets/privacy_tab.dart +++ b/lib/features/profile/presentation/widgets/privacy_tab.dart @@ -14,22 +14,14 @@ class PrivacyTab extends ConsumerStatefulWidget { class _PrivacyTabState extends ConsumerState { String _profileVisibility = 'public'; - String _contactInfo = 'connections'; String _activityStatus = 'public'; - bool _shareAnalytics = false; - bool _personalizedAds = false; - bool _thirdPartySharing = false; bool _isLoadingPrivacy = false; bool _isSavingPrivacy = false; bool _privacyLoaded = false; // Snapshot for cancel/reset String _origProfileVisibility = 'public'; - String _origContactInfo = 'connections'; String _origActivityStatus = 'public'; - bool _origShareAnalytics = false; - bool _origPersonalizedAds = false; - bool _origThirdPartySharing = false; @override void initState() { @@ -45,26 +37,14 @@ class _PrivacyTabState extends ConsumerState { final repo = ref.read(profileRepositoryProvider); final data = await repo.getPrivacyPreferences(role); final privacy = data['privacySettings'] as Map? ?? {}; - final dataSettings = - data['dataSettings'] as Map? ?? {}; setState(() { _profileVisibility = privacy['profile_visibility'] as String? ?? 'public'; - _contactInfo = privacy['contact_info'] as String? ?? 'connections'; _activityStatus = privacy['activity_status'] as String? ?? 'public'; - _shareAnalytics = dataSettings['shareAnalytics'] as bool? ?? false; - _personalizedAds = dataSettings['personalizedAds'] as bool? ?? false; - _thirdPartySharing = - dataSettings['thirdPartySharing'] as bool? ?? false; _isLoadingPrivacy = false; _privacyLoaded = true; - // Save snapshot for cancel/reset _origProfileVisibility = _profileVisibility; - _origContactInfo = _contactInfo; _origActivityStatus = _activityStatus; - _origShareAnalytics = _shareAnalytics; - _origPersonalizedAds = _personalizedAds; - _origThirdPartySharing = _thirdPartySharing; }); } catch (_) { setState(() => _isLoadingPrivacy = false); @@ -79,6 +59,8 @@ class _PrivacyTabState extends ConsumerState { child: CircularProgressIndicator(color: AppColors.accentOrange)); } + final isAgent = ref.read(profileProvider).role == 'AGENT'; + return SingleChildScrollView( padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16), child: Column( @@ -89,32 +71,23 @@ class _PrivacyTabState extends ConsumerState { subtitle: 'Control your privacy and visibility preferences', child: Column( children: [ - ProfileDropdownRow( - label: 'Profile Visibility', - description: 'Control who can see your profile', - value: _profileVisibility, - options: const { - 'public': 'Public', - 'connections': 'Connections Only', - 'private': 'Private', - }, - onChanged: (v) => - setState(() => _profileVisibility = v ?? _profileVisibility), - ), - const Divider(height: 24, color: Color(0xFFE8E8E8)), - ProfileDropdownRow( - label: 'Contact Information', - description: 'Control who can see your contact details', - value: _contactInfo, - options: const { - 'public': 'Public', - 'connections': 'Connections Only', - 'private': 'Hidden', - }, - onChanged: (v) => - setState(() => _contactInfo = v ?? _contactInfo), - ), - const Divider(height: 24, color: Color(0xFFE8E8E8)), + // Profile Visibility — agent only + if (isAgent) ...[ + ProfileDropdownRow( + label: 'Profile Visibility', + description: 'Control who can see your profile', + value: _profileVisibility, + options: const { + 'public': 'Public', + 'connections': 'Connections Only', + 'private': 'Private', + }, + onChanged: (v) => + setState(() => _profileVisibility = v ?? _profileVisibility), + ), + const Divider(height: 24, color: Color(0xFFE8E8E8)), + ], + // Activity Status — both agent and user ProfileDropdownRow( label: 'Activity Status', description: 'Show when you are active on the platform', @@ -131,86 +104,37 @@ class _PrivacyTabState extends ConsumerState { ), ), const SizedBox(height: 20), - ProfileSectionCard( - title: 'Data & Personalization', - subtitle: 'Manage how your data is used', - child: Column( - children: [ - ProfileToggleRow( - label: 'Share Analytics', - description: - 'Help improve our service by sharing usage data', - value: _shareAnalytics, - onChanged: (v) => setState(() => _shareAnalytics = v), - ), - const Divider(height: 24, color: Color(0xFFE8E8E8)), - ProfileToggleRow( - label: 'Personalized Ads', - description: 'See ads tailored to your interests', - value: _personalizedAds, - onChanged: (v) => setState(() => _personalizedAds = v), - ), - const Divider(height: 24, color: Color(0xFFE8E8E8)), - ProfileToggleRow( - label: 'Third-Party Data Sharing', - description: - 'Allow sharing data with third-party partners', - value: _thirdPartySharing, - onChanged: (v) => setState(() => _thirdPartySharing = v), - ), - ], - ), - ), - const SizedBox(height: 20), ProfileActionButtons( onSave: _savePrivacyPreferences, onCancel: () { setState(() { _profileVisibility = _origProfileVisibility; - _contactInfo = _origContactInfo; _activityStatus = _origActivityStatus; - _shareAnalytics = _origShareAnalytics; - _personalizedAds = _origPersonalizedAds; - _thirdPartySharing = _origThirdPartySharing; }); }, isSaving: _isSavingPrivacy), const SizedBox(height: 24), + // Delete Account ProfileSectionCard( - title: 'Danger Zone', - subtitle: 'Irreversible and destructive actions', - borderColor: Colors.red.withValues(alpha: 0.3), - titleColor: Colors.red, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Once you delete your account, there is no going back. All your data will be permanently removed.', - style: TextStyle( - fontFamily: 'SourceSerif4', - fontSize: 13, - color: AppColors.hintText), + title: 'Delete Account', + subtitle: 'Permanently delete your account and all data', + child: SizedBox( + width: double.infinity, + child: OutlinedButton( + onPressed: _deleteAccount, + style: OutlinedButton.styleFrom( + foregroundColor: Colors.red, + side: const BorderSide(color: Colors.red, width: 1.5), + padding: const EdgeInsets.symmetric(vertical: 14), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15)), ), - const SizedBox(height: 16), - SizedBox( - width: double.infinity, - child: OutlinedButton( - onPressed: _deleteAccount, - style: OutlinedButton.styleFrom( - foregroundColor: Colors.red, - side: const BorderSide(color: Colors.red, width: 1.5), - padding: const EdgeInsets.symmetric(vertical: 14), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(15)), - ), - child: const Text('Delete Account', - style: TextStyle( - fontFamily: 'Fractul', - fontSize: 14, - fontWeight: FontWeight.w700)), - ), - ), - ], + child: const Text('Delete Account', + style: TextStyle( + fontFamily: 'Fractul', + fontSize: 14, + fontWeight: FontWeight.w700)), + ), ), ), const SizedBox(height: 32), @@ -227,14 +151,8 @@ class _PrivacyTabState extends ConsumerState { await repo.updatePrivacyPreferences(role, { 'privacySettings': { 'profile_visibility': _profileVisibility, - 'contact_info': _contactInfo, 'activity_status': _activityStatus, }, - 'dataSettings': { - 'shareAnalytics': _shareAnalytics, - 'personalizedAds': _personalizedAds, - 'thirdPartySharing': _thirdPartySharing, - }, }); _showSnackBar('Privacy settings saved'); } catch (e) {