Compare commits
2 Commits
4d3cc94071
...
d82cac35f2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d82cac35f2 | ||
| 471ce430b0 |
@ -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);
|
||||
}
|
||||
|
||||
@ -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<String, dynamic> 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'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
|
||||
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<PatientAddressScreen> {
|
||||
_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<PatientAddressScreen> {
|
||||
),
|
||||
),
|
||||
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<PatientAddressScreen> {
|
||||
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<PatientAddressScreen> {
|
||||
_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<PatientAddressScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
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<PatientAddressScreen> {
|
||||
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<PatientAddressScreen> {
|
||||
_lineController.dispose();
|
||||
_townController.dispose();
|
||||
_pincodeController.dispose();
|
||||
_otherLabelController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,6 +137,8 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
|
||||
}
|
||||
|
||||
void _showResultDialog(bool isSuccess) {
|
||||
if (!mounted) return;
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
@ -178,14 +180,7 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
|
||||
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<PatientRegistrationScreen> {
|
||||
_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<PatientRegistrationScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _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<PatientRegistrationScreen> {
|
||||
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user