diff --git a/lib/controllers/patient_controller.dart b/lib/controllers/patient_controller.dart index e408271..dc2b961 100644 --- a/lib/controllers/patient_controller.dart +++ b/lib/controllers/patient_controller.dart @@ -57,14 +57,6 @@ class PatientController { model.address.city = city; } - void updateAddressType(String addressType) { - model.address.addressType = addressType; - } - - void updateOtherLabel(String otherLabel) { - model.address.otherLabel = otherLabel; - } - void addFamilyMember(FamilyMember member) { model.familyMembers.add(member); } diff --git a/lib/data/models/patient.dart b/lib/data/models/patient.dart index 5dcd4e0..52fc057 100644 --- a/lib/data/models/patient.dart +++ b/lib/data/models/patient.dart @@ -92,20 +92,15 @@ class PatientAddress { String? country; String? state; String? city; - String? addressType; - String? otherLabel; - PatientAddress({ - this.houseNo, - this.line, - this.town, - this.pincode, - this.country, - this.state, - this.city, - this.addressType, - this.otherLabel, - }); + PatientAddress( + {this.houseNo, + this.line, + this.town, + this.pincode, + this.country, + this.state, + this.city}); Map toJson() { return { @@ -116,8 +111,6 @@ class PatientAddress { 'country': country, 'state': state, 'city': city, - 'addressType': addressType, - 'otherLabel': otherLabel, }; } @@ -129,7 +122,5 @@ class PatientAddress { country = json['country']; state = json['state']; city = json['city']; - addressType = json['addressType']; - otherLabel = json['otherLabel']; } } diff --git a/lib/screens/patient_screens/registration_screens/patient_adress_screen.dart b/lib/screens/patient_screens/registration_screens/patient_adress_screen.dart index 9b9f877..a69441a 100644 --- a/lib/screens/patient_screens/registration_screens/patient_adress_screen.dart +++ b/lib/screens/patient_screens/registration_screens/patient_adress_screen.dart @@ -17,7 +17,6 @@ class _PatientAddressScreenState extends State { late TextEditingController _lineController; late TextEditingController _townController; late TextEditingController _pincodeController; - late TextEditingController _otherLabelController; final String country = 'India'; String? state; String? city; @@ -38,11 +37,9 @@ class _PatientAddressScreenState extends State { _lineController = TextEditingController(text: address.line ?? ''); _townController = TextEditingController(text: address.town ?? ''); _pincodeController = TextEditingController(text: address.pincode ?? ''); - _otherLabelController = - TextEditingController(text: address.otherLabel ?? ''); + state = address.state; city = address.city; - addressType = address.addressType; } @override @@ -140,21 +137,6 @@ class _PatientAddressScreenState extends State { ), ), const SizedBox(height: 20), - _buildSectionContainer( - 'Address Type', - Column( - children: [ - _buildAddressTypeChips(), - if (addressType == 'Other') - _buildTextField( - 'Other Label', - _otherLabelController, - (value) => widget.controller!.updateOtherLabel(value), - icon: Icons.label_outline, - ), - ], - ), - ), ], ), ), @@ -180,7 +162,7 @@ class _PatientAddressScreenState extends State { if (pincode.isEmpty) { _errors['pincode'] = 'Pincode is required'; _hasErrors = true; - } else if (!RegExp(r'^\d{6}$').hasMatch(pincode)) { + } else if (!RegExp(r'^[1-9][0-9]{5}$').hasMatch(pincode)) { _errors['pincode'] = 'Enter a valid 6-digit pincode'; _hasErrors = true; } @@ -194,16 +176,6 @@ class _PatientAddressScreenState extends State { _errors['city'] = 'City is required'; _hasErrors = true; } - - if (addressType == null || addressType!.isEmpty) { - _errors['addressType'] = 'Please select an address type'; - _hasErrors = true; - } - - if (addressType == 'Other' && _otherLabelController.text.trim().isEmpty) { - _errors['otherLabel'] = 'Please specify other label'; - _hasErrors = true; - } }); return !_hasErrors; @@ -301,24 +273,6 @@ class _PatientAddressScreenState extends State { ); } - Widget _buildAddressTypeChips() { - return Wrap( - spacing: 8.0, - children: ['Home', 'Office', 'Other'].map((String type) { - return ChoiceChip( - label: Text(type), - selected: addressType == type, - onSelected: (bool selected) { - setState(() { - addressType = selected ? type : addressType; - }); - widget.controller!.updateAddressType(addressType!); - }, - ); - }).toList(), - ); - } - void _saveAndExit() { if (_validateFields()) { widget.controller!.updateHouseNo(_houseNoController.text); @@ -328,8 +282,7 @@ class _PatientAddressScreenState extends State { widget.controller!.updateCountry(country); widget.controller!.updateState(state ?? ''); widget.controller!.updateCity(city ?? ''); - widget.controller!.updateAddressType(addressType ?? ''); - widget.controller!.updateOtherLabel(_otherLabelController.text); + widget.controller!.updatePatientData(); Navigator.pop(context, true); } else { @@ -375,7 +328,6 @@ class _PatientAddressScreenState extends State { _lineController.dispose(); _townController.dispose(); _pincodeController.dispose(); - _otherLabelController.dispose(); super.dispose(); } } diff --git a/lib/screens/patient_screens/registration_screens/patient_registration_screen.dart b/lib/screens/patient_screens/registration_screens/patient_registration_screen.dart index 2b2af16..1cacbe2 100644 --- a/lib/screens/patient_screens/registration_screens/patient_registration_screen.dart +++ b/lib/screens/patient_screens/registration_screens/patient_registration_screen.dart @@ -137,6 +137,8 @@ class _PatientRegistrationScreenState extends State { } void _showResultDialog(bool isSuccess) { + if (!mounted) return; + Navigator.push( context, MaterialPageRoute( @@ -178,14 +180,7 @@ class _PatientRegistrationScreenState extends State { Padding( padding: const EdgeInsets.all(8.0), child: IconButton( - onPressed: () { - if (_validateAllFields()) { - _controller.savePatientData(); - _showResultDialog(true); - } else { - _showValidationErrors(); - } - }, + onPressed: _handleProfileSave, icon: const Icon(Icons.check, color: Colors.blue, weight: 50), ), ), @@ -556,12 +551,6 @@ class _PatientRegistrationScreenState extends State { _errors['address'] = 'Please complete all required address fields'; _hasErrors = true; } - - if (address.addressType == 'Other' && - (address.otherLabel?.isEmpty ?? true)) { - _errors['address'] = 'Please specify other address label'; - _hasErrors = true; - } }); return !_hasErrors; @@ -603,6 +592,27 @@ class _PatientRegistrationScreenState extends State { ); } + Future _handleProfileSave() async { + if (_validateAllFields()) { + try { + final bool isSuccess = await _controller.savePatientData(); + if (mounted) { + Navigator.pop(context); + } + + _showResultDialog(isSuccess); + } catch (e) { + if (mounted) { + Navigator.pop(context); + } + + _showResultDialog(false); + } + } else { + _showValidationErrors(); + } + } + Widget _buildNavigationField( String label, IconData icon, VoidCallback onTap) { bool isAddressField = label == 'Address'; @@ -672,8 +682,7 @@ class _PatientRegistrationScreenState extends State { return Text( '${address.houseNo}, ${address.line}\n' - '${address.city}, ${address.state} ${address.pincode}\n' - '${address.addressType}${address.addressType == "Other" ? ": ${address.otherLabel}" : ""}', + '${address.city}, ${address.state} ${address.pincode}\n', style: const TextStyle(color: Colors.black87), ); }