From aaed88d51d9400158d79cf80bba724dc8a330d18 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sun, 15 Mar 2026 22:40:24 +0530 Subject: [PATCH] Refactor: Change profile tab cancel actions to reset form state instead of navigating, and adjust agent availability UI. --- .../presentation/screens/agent_home_screen.dart | 11 +---------- .../presentation/widgets/change_password_tab.dart | 12 ++++++++++-- .../presentation/widgets/notifications_tab.dart | 6 ++++-- .../profile/presentation/widgets/privacy_tab.dart | 6 ++++-- .../presentation/widgets/profile_settings_tab.dart | 13 +++++++++++-- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/features/agents/presentation/screens/agent_home_screen.dart b/lib/features/agents/presentation/screens/agent_home_screen.dart index 807e59d..27c82d3 100644 --- a/lib/features/agents/presentation/screens/agent_home_screen.dart +++ b/lib/features/agents/presentation/screens/agent_home_screen.dart @@ -438,16 +438,7 @@ class _AgentHomeContentState extends ConsumerState<_AgentHomeContent> { ), ), const Spacer(), - if (_isTogglingAvailability && !isActive) - const SizedBox( - width: 16, - height: 16, - child: CircularProgressIndicator( - strokeWidth: 2, - color: AppColors.accentOrange, - ), - ) - else if (isActive) + if (isActive) Text( 'Active', style: TextStyle( diff --git a/lib/features/profile/presentation/widgets/change_password_tab.dart b/lib/features/profile/presentation/widgets/change_password_tab.dart index 09977bc..0adccb2 100644 --- a/lib/features/profile/presentation/widgets/change_password_tab.dart +++ b/lib/features/profile/presentation/widgets/change_password_tab.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:go_router/go_router.dart'; import 'package:real_estate_mobile/core/constants/app_colors.dart'; import 'package:real_estate_mobile/features/profile/presentation/providers/profile_provider.dart'; import 'package:real_estate_mobile/features/profile/presentation/widgets/profile_shared_widgets.dart'; @@ -90,7 +89,16 @@ class _ChangePasswordTabState extends ConsumerState { const SizedBox(height: 40), ProfileActionButtons( onSave: _changePassword, - onCancel: () => context.go('/home'), + onCancel: () { + _currentPasswordController.clear(); + _newPasswordController.clear(); + _confirmPasswordController.clear(); + setState(() { + _showCurrentPassword = false; + _showNewPassword = false; + _showConfirmPassword = false; + }); + }, isSaving: _isChangingPassword, saveLabel: 'Update Password', ), diff --git a/lib/features/profile/presentation/widgets/notifications_tab.dart b/lib/features/profile/presentation/widgets/notifications_tab.dart index 5231c7c..e5f1024 100644 --- a/lib/features/profile/presentation/widgets/notifications_tab.dart +++ b/lib/features/profile/presentation/widgets/notifications_tab.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:go_router/go_router.dart'; import 'package:real_estate_mobile/core/constants/app_colors.dart'; import 'package:real_estate_mobile/features/profile/presentation/providers/profile_provider.dart'; import 'package:real_estate_mobile/features/profile/presentation/widgets/profile_shared_widgets.dart'; @@ -144,7 +143,10 @@ class _NotificationsTabState extends ConsumerState { const SizedBox(height: 40), ProfileActionButtons( onSave: _saveNotificationSettings, - onCancel: () => context.go('/home'), + onCancel: () { + _notificationsLoaded = false; + _loadNotificationPreferences(); + }, isSaving: _isSavingNotifications, ), ], diff --git a/lib/features/profile/presentation/widgets/privacy_tab.dart b/lib/features/profile/presentation/widgets/privacy_tab.dart index 4e313d9..88af8fd 100644 --- a/lib/features/profile/presentation/widgets/privacy_tab.dart +++ b/lib/features/profile/presentation/widgets/privacy_tab.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:go_router/go_router.dart'; import 'package:real_estate_mobile/core/constants/app_colors.dart'; import 'package:real_estate_mobile/features/auth/presentation/providers/auth_provider.dart'; import 'package:real_estate_mobile/features/profile/presentation/providers/profile_provider.dart'; @@ -150,7 +149,10 @@ class _PrivacyTabState extends ConsumerState { const SizedBox(height: 20), ProfileActionButtons( onSave: _savePrivacyPreferences, - onCancel: () => context.go('/home'), + onCancel: () { + _privacyLoaded = false; + _loadPrivacyPreferences(); + }, isSaving: _isSavingPrivacy), const SizedBox(height: 24), ProfileSectionCard( diff --git a/lib/features/profile/presentation/widgets/profile_settings_tab.dart b/lib/features/profile/presentation/widgets/profile_settings_tab.dart index c0b26e6..99c8fb4 100644 --- a/lib/features/profile/presentation/widgets/profile_settings_tab.dart +++ b/lib/features/profile/presentation/widgets/profile_settings_tab.dart @@ -3,7 +3,6 @@ import 'dart:io'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:go_router/go_router.dart'; import 'package:image_picker/image_picker.dart'; import 'package:real_estate_mobile/core/constants/app_colors.dart'; import 'package:real_estate_mobile/core/utils/image_url_resolver.dart'; @@ -261,7 +260,7 @@ class _ProfileSettingsTabState extends ConsumerState { const SizedBox(height: 30), ProfileActionButtons( onSave: _saveProfileSettings, - onCancel: () => context.go('/home'), + onCancel: _resetForm, isSaving: profileState.isSaving, ), ], @@ -337,6 +336,16 @@ class _ProfileSettingsTabState extends ConsumerState { if (mounted) _showSnackBar('Avatar deleted'); } + void _resetForm() { + _controllersInitialized = false; + _localAvatarFile = null; + final profileState = ref.read(profileProvider); + if (profileState.profile.isNotEmpty) { + _initControllersFromProfile(profileState); + } + setState(() {}); + } + void _saveProfileSettings() { final profileState = ref.read(profileProvider); final isAgent = profileState.isAgent;