Refactor: Change profile tab cancel actions to reset form state instead of navigating, and adjust agent availability UI.

This commit is contained in:
pradeepkumar
2026-03-15 22:40:24 +05:30
parent f6263b833c
commit aaed88d51d
5 changed files with 30 additions and 18 deletions

View File

@@ -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(

View File

@@ -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<ChangePasswordTab> {
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',
),

View File

@@ -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<NotificationsTab> {
const SizedBox(height: 40),
ProfileActionButtons(
onSave: _saveNotificationSettings,
onCancel: () => context.go('/home'),
onCancel: () {
_notificationsLoaded = false;
_loadNotificationPreferences();
},
isSaving: _isSavingNotifications,
),
],

View File

@@ -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<PrivacyTab> {
const SizedBox(height: 20),
ProfileActionButtons(
onSave: _savePrivacyPreferences,
onCancel: () => context.go('/home'),
onCancel: () {
_privacyLoaded = false;
_loadPrivacyPreferences();
},
isSaving: _isSavingPrivacy),
const SizedBox(height: 24),
ProfileSectionCard(

View File

@@ -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<ProfileSettingsTab> {
const SizedBox(height: 30),
ProfileActionButtons(
onSave: _saveProfileSettings,
onCancel: () => context.go('/home'),
onCancel: _resetForm,
isSaving: profileState.isSaving,
),
],
@@ -337,6 +336,16 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
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;