fix: update privacy state after save and enforce 10-digit phone number validation in profile settings
This commit is contained in:
@@ -154,6 +154,13 @@ class _PrivacyTabState extends ConsumerState<PrivacyTab> {
|
||||
'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);
|
||||
|
||||
@@ -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<ProfileSettingsTab> {
|
||||
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<ProfileSettingsTab> {
|
||||
}
|
||||
|
||||
Future<void> _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<ProfileSettingsTab> {
|
||||
final data = <String, dynamic>{
|
||||
'firstName': firstName,
|
||||
'lastName': lastName,
|
||||
'phone': _phoneController.text.trim(),
|
||||
'phone': phone,
|
||||
};
|
||||
|
||||
await ref.read(profileProvider.notifier).updateProfile(data);
|
||||
|
||||
Reference in New Issue
Block a user