refactor: remove location field and related logic from profile settings tab
This commit is contained in:
@@ -23,7 +23,6 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
late TextEditingController _titleController;
|
||||
late TextEditingController _emailController;
|
||||
late TextEditingController _phoneController;
|
||||
late TextEditingController _locationController;
|
||||
|
||||
bool _controllersInitialized = false;
|
||||
bool _isUploadingAvatar = false;
|
||||
@@ -37,12 +36,10 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
_titleController = TextEditingController();
|
||||
_emailController = TextEditingController();
|
||||
_phoneController = TextEditingController();
|
||||
_locationController = TextEditingController();
|
||||
// Listen for changes to enable/disable Cancel & Save buttons
|
||||
_fullNameController.addListener(_onFieldChanged);
|
||||
_titleController.addListener(_onFieldChanged);
|
||||
_phoneController.addListener(_onFieldChanged);
|
||||
_locationController.addListener(_onFieldChanged);
|
||||
}
|
||||
|
||||
void _onFieldChanged() {
|
||||
@@ -54,12 +51,10 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
_fullNameController.removeListener(_onFieldChanged);
|
||||
_titleController.removeListener(_onFieldChanged);
|
||||
_phoneController.removeListener(_onFieldChanged);
|
||||
_locationController.removeListener(_onFieldChanged);
|
||||
_fullNameController.dispose();
|
||||
_titleController.dispose();
|
||||
_emailController.dispose();
|
||||
_phoneController.dispose();
|
||||
_locationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -83,17 +78,8 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
final agentType = profile['agentType'] as Map<String, dynamic>?;
|
||||
_titleController.text =
|
||||
agentType?['name'] as String? ?? profile['bio'] as String? ?? '';
|
||||
final serviceAreas = profile['serviceAreas'];
|
||||
if (serviceAreas is List && serviceAreas.isNotEmpty) {
|
||||
_locationController.text = serviceAreas.first.toString();
|
||||
}
|
||||
} else {
|
||||
_titleController.text = profile['headline'] as String? ?? '';
|
||||
final city = profile['city'] as String? ?? '';
|
||||
final stateName = profile['state'] as String? ?? '';
|
||||
final country = profile['country'] as String? ?? '';
|
||||
final parts = [stateName, city, country].where((s) => s.isNotEmpty);
|
||||
_locationController.text = parts.join(', ');
|
||||
}
|
||||
|
||||
_savedValues = {
|
||||
@@ -101,15 +87,13 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
'title': _titleController.text,
|
||||
'email': _emailController.text,
|
||||
'phone': _phoneController.text,
|
||||
'location': _locationController.text,
|
||||
};
|
||||
}
|
||||
|
||||
bool get _hasChanges {
|
||||
return _fullNameController.text != (_savedValues['fullName'] ?? '') ||
|
||||
_titleController.text != (_savedValues['title'] ?? '') ||
|
||||
_phoneController.text != (_savedValues['phone'] ?? '') ||
|
||||
_locationController.text != (_savedValues['location'] ?? '');
|
||||
_phoneController.text != (_savedValues['phone'] ?? '');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -282,12 +266,6 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
controller: _phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
textCapitalization: TextCapitalization.none),
|
||||
const SizedBox(height: 24),
|
||||
ProfileFormField(
|
||||
label: isAgent ? 'Service Areas' : 'Location',
|
||||
controller: _locationController,
|
||||
prefixIcon: Icons.location_on,
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
ProfileActionButtons(
|
||||
onSave: _saveProfileSettings,
|
||||
@@ -375,14 +353,10 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
_fullNameController.text = _savedValues['fullName'] ?? '';
|
||||
_titleController.text = _savedValues['title'] ?? '';
|
||||
_phoneController.text = _savedValues['phone'] ?? '';
|
||||
_locationController.text = _savedValues['location'] ?? '';
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Future<void> _saveProfileSettings() async {
|
||||
final profileState = ref.read(profileProvider);
|
||||
final isAgent = profileState.isAgent;
|
||||
|
||||
final nameParts = _fullNameController.text.trim().split(RegExp(r'\s+'));
|
||||
final firstName = nameParts.first;
|
||||
final lastName =
|
||||
@@ -394,21 +368,6 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
'phone': _phoneController.text.trim(),
|
||||
};
|
||||
|
||||
if (isAgent) {
|
||||
final location = _locationController.text.trim();
|
||||
if (location.isNotEmpty) data['serviceAreas'] = [location];
|
||||
} else {
|
||||
final locationParts = _locationController.text
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.where((s) => s.isNotEmpty)
|
||||
.toList();
|
||||
// Display order is state first, then city, then country — parse in the same order
|
||||
if (locationParts.isNotEmpty) data['state'] = locationParts[0];
|
||||
if (locationParts.length > 1) data['city'] = locationParts[1];
|
||||
if (locationParts.length > 2) data['country'] = locationParts[2];
|
||||
}
|
||||
|
||||
await ref.read(profileProvider.notifier).updateProfile(data);
|
||||
|
||||
// Update saved values so Cancel won't revert after successful save
|
||||
@@ -419,7 +378,6 @@ class _ProfileSettingsTabState extends ConsumerState<ProfileSettingsTab> {
|
||||
'title': _titleController.text,
|
||||
'email': _emailController.text,
|
||||
'phone': _phoneController.text,
|
||||
'location': _locationController.text,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user