diff --git a/lib/features/profile/presentation/widgets/privacy_tab.dart b/lib/features/profile/presentation/widgets/privacy_tab.dart index 91723ff..46db754 100644 --- a/lib/features/profile/presentation/widgets/privacy_tab.dart +++ b/lib/features/profile/presentation/widgets/privacy_tab.dart @@ -154,6 +154,13 @@ class _PrivacyTabState extends ConsumerState { 'activity_status': _activityStatus, }, }); + // Update the snapshot so a later Cancel doesn't revert the just-saved values + if (mounted) { + setState(() { + _origProfileVisibility = _profileVisibility; + _origActivityStatus = _activityStatus; + }); + } _showSnackBar('Privacy settings saved'); } catch (e) { _showSnackBar('Failed to save: $e', isError: true); diff --git a/lib/features/profile/presentation/widgets/profile_settings_tab.dart b/lib/features/profile/presentation/widgets/profile_settings_tab.dart index e0edc22..27abc6e 100644 --- a/lib/features/profile/presentation/widgets/profile_settings_tab.dart +++ b/lib/features/profile/presentation/widgets/profile_settings_tab.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:image_picker/image_picker.dart'; import 'package:real_estate_mobile/core/constants/app_colors.dart'; @@ -262,10 +263,14 @@ class _ProfileSettingsTabState extends ConsumerState { textCapitalization: TextCapitalization.none), const SizedBox(height: 24), ProfileFormField( - label: 'Phone Number', - controller: _phoneController, - keyboardType: TextInputType.phone, - textCapitalization: TextCapitalization.none), + label: 'Phone Number', + controller: _phoneController, + keyboardType: TextInputType.phone, + textCapitalization: TextCapitalization.none, + // Digits only, max 10 (US format) — matches admin panel rule + inputFormatters: [FilteringTextInputFormatter.digitsOnly], + maxLength: 10, + ), const SizedBox(height: 30), ProfileActionButtons( onSave: _saveProfileSettings, @@ -357,6 +362,13 @@ class _ProfileSettingsTabState extends ConsumerState { } Future _saveProfileSettings() async { + // Validate phone: must be empty (optional) OR exactly 10 digits + final phone = _phoneController.text.trim(); + if (phone.isNotEmpty && phone.length != 10) { + _showSnackBar('Phone number must be exactly 10 digits', isError: true); + throw Exception('Invalid phone number'); + } + final nameParts = _fullNameController.text.trim().split(RegExp(r'\s+')); final firstName = nameParts.first; final lastName = @@ -365,7 +377,7 @@ class _ProfileSettingsTabState extends ConsumerState { final data = { 'firstName': firstName, 'lastName': lastName, - 'phone': _phoneController.text.trim(), + 'phone': phone, }; await ref.read(profileProvider.notifier).updateProfile(data);