Compare commits

..

No commits in common. "d82cac35f26b696b0713552409d32eb03810bd40" and "4d3cc94071268dd4a28f43e51e52081c10097db8" have entirely different histories.

4 changed files with 92 additions and 36 deletions

View File

@ -57,6 +57,14 @@ 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);
}

View File

@ -92,15 +92,20 @@ 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});
PatientAddress({
this.houseNo,
this.line,
this.town,
this.pincode,
this.country,
this.state,
this.city,
this.addressType,
this.otherLabel,
});
Map<String, dynamic> toJson() {
return {
@ -111,6 +116,8 @@ class PatientAddress {
'country': country,
'state': state,
'city': city,
'addressType': addressType,
'otherLabel': otherLabel,
};
}
@ -122,5 +129,7 @@ class PatientAddress {
country = json['country'];
state = json['state'];
city = json['city'];
addressType = json['addressType'];
otherLabel = json['otherLabel'];
}
}

View File

@ -17,6 +17,7 @@ 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;
@ -37,9 +38,11 @@ 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
@ -137,6 +140,21 @@ 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,
),
],
),
),
],
),
),
@ -162,7 +180,7 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
if (pincode.isEmpty) {
_errors['pincode'] = 'Pincode is required';
_hasErrors = true;
} else if (!RegExp(r'^[1-9][0-9]{5}$').hasMatch(pincode)) {
} else if (!RegExp(r'^\d{6}$').hasMatch(pincode)) {
_errors['pincode'] = 'Enter a valid 6-digit pincode';
_hasErrors = true;
}
@ -176,6 +194,16 @@ 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;
@ -273,6 +301,24 @@ 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);
@ -282,7 +328,8 @@ 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 {
@ -328,6 +375,7 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
_lineController.dispose();
_townController.dispose();
_pincodeController.dispose();
_otherLabelController.dispose();
super.dispose();
}
}

View File

@ -137,8 +137,6 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
}
void _showResultDialog(bool isSuccess) {
if (!mounted) return;
Navigator.push(
context,
MaterialPageRoute(
@ -180,7 +178,14 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
Padding(
padding: const EdgeInsets.all(8.0),
child: IconButton(
onPressed: _handleProfileSave,
onPressed: () {
if (_validateAllFields()) {
_controller.savePatientData();
_showResultDialog(true);
} else {
_showValidationErrors();
}
},
icon: const Icon(Icons.check, color: Colors.blue, weight: 50),
),
),
@ -551,6 +556,12 @@ 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;
@ -592,27 +603,6 @@ 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';
@ -682,7 +672,8 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
return Text(
'${address.houseNo}, ${address.line}\n'
'${address.city}, ${address.state} ${address.pincode}\n',
'${address.city}, ${address.state} ${address.pincode}\n'
'${address.addressType}${address.addressType == "Other" ? ": ${address.otherLabel}" : ""}',
style: const TextStyle(color: Colors.black87),
);
}