Compare commits
No commits in common. "d82cac35f26b696b0713552409d32eb03810bd40" and "4d3cc94071268dd4a28f43e51e52081c10097db8" have entirely different histories.
d82cac35f2
...
4d3cc94071
@ -57,6 +57,14 @@ class PatientController {
|
|||||||
model.address.city = city;
|
model.address.city = city;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateAddressType(String addressType) {
|
||||||
|
model.address.addressType = addressType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateOtherLabel(String otherLabel) {
|
||||||
|
model.address.otherLabel = otherLabel;
|
||||||
|
}
|
||||||
|
|
||||||
void addFamilyMember(FamilyMember member) {
|
void addFamilyMember(FamilyMember member) {
|
||||||
model.familyMembers.add(member);
|
model.familyMembers.add(member);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,15 +92,20 @@ class PatientAddress {
|
|||||||
String? country;
|
String? country;
|
||||||
String? state;
|
String? state;
|
||||||
String? city;
|
String? city;
|
||||||
|
String? addressType;
|
||||||
|
String? otherLabel;
|
||||||
|
|
||||||
PatientAddress(
|
PatientAddress({
|
||||||
{this.houseNo,
|
this.houseNo,
|
||||||
this.line,
|
this.line,
|
||||||
this.town,
|
this.town,
|
||||||
this.pincode,
|
this.pincode,
|
||||||
this.country,
|
this.country,
|
||||||
this.state,
|
this.state,
|
||||||
this.city});
|
this.city,
|
||||||
|
this.addressType,
|
||||||
|
this.otherLabel,
|
||||||
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
@ -111,6 +116,8 @@ class PatientAddress {
|
|||||||
'country': country,
|
'country': country,
|
||||||
'state': state,
|
'state': state,
|
||||||
'city': city,
|
'city': city,
|
||||||
|
'addressType': addressType,
|
||||||
|
'otherLabel': otherLabel,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,5 +129,7 @@ class PatientAddress {
|
|||||||
country = json['country'];
|
country = json['country'];
|
||||||
state = json['state'];
|
state = json['state'];
|
||||||
city = json['city'];
|
city = json['city'];
|
||||||
|
addressType = json['addressType'];
|
||||||
|
otherLabel = json['otherLabel'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
|
|||||||
late TextEditingController _lineController;
|
late TextEditingController _lineController;
|
||||||
late TextEditingController _townController;
|
late TextEditingController _townController;
|
||||||
late TextEditingController _pincodeController;
|
late TextEditingController _pincodeController;
|
||||||
|
late TextEditingController _otherLabelController;
|
||||||
final String country = 'India';
|
final String country = 'India';
|
||||||
String? state;
|
String? state;
|
||||||
String? city;
|
String? city;
|
||||||
@ -37,9 +38,11 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
|
|||||||
_lineController = TextEditingController(text: address.line ?? '');
|
_lineController = TextEditingController(text: address.line ?? '');
|
||||||
_townController = TextEditingController(text: address.town ?? '');
|
_townController = TextEditingController(text: address.town ?? '');
|
||||||
_pincodeController = TextEditingController(text: address.pincode ?? '');
|
_pincodeController = TextEditingController(text: address.pincode ?? '');
|
||||||
|
_otherLabelController =
|
||||||
|
TextEditingController(text: address.otherLabel ?? '');
|
||||||
state = address.state;
|
state = address.state;
|
||||||
city = address.city;
|
city = address.city;
|
||||||
|
addressType = address.addressType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -137,6 +140,21 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
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) {
|
if (pincode.isEmpty) {
|
||||||
_errors['pincode'] = 'Pincode is required';
|
_errors['pincode'] = 'Pincode is required';
|
||||||
_hasErrors = true;
|
_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';
|
_errors['pincode'] = 'Enter a valid 6-digit pincode';
|
||||||
_hasErrors = true;
|
_hasErrors = true;
|
||||||
}
|
}
|
||||||
@ -176,6 +194,16 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
|
|||||||
_errors['city'] = 'City is required';
|
_errors['city'] = 'City is required';
|
||||||
_hasErrors = true;
|
_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;
|
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() {
|
void _saveAndExit() {
|
||||||
if (_validateFields()) {
|
if (_validateFields()) {
|
||||||
widget.controller!.updateHouseNo(_houseNoController.text);
|
widget.controller!.updateHouseNo(_houseNoController.text);
|
||||||
@ -282,7 +328,8 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
|
|||||||
widget.controller!.updateCountry(country);
|
widget.controller!.updateCountry(country);
|
||||||
widget.controller!.updateState(state ?? '');
|
widget.controller!.updateState(state ?? '');
|
||||||
widget.controller!.updateCity(city ?? '');
|
widget.controller!.updateCity(city ?? '');
|
||||||
|
widget.controller!.updateAddressType(addressType ?? '');
|
||||||
|
widget.controller!.updateOtherLabel(_otherLabelController.text);
|
||||||
widget.controller!.updatePatientData();
|
widget.controller!.updatePatientData();
|
||||||
Navigator.pop(context, true);
|
Navigator.pop(context, true);
|
||||||
} else {
|
} else {
|
||||||
@ -328,6 +375,7 @@ class _PatientAddressScreenState extends State<PatientAddressScreen> {
|
|||||||
_lineController.dispose();
|
_lineController.dispose();
|
||||||
_townController.dispose();
|
_townController.dispose();
|
||||||
_pincodeController.dispose();
|
_pincodeController.dispose();
|
||||||
|
_otherLabelController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,8 +137,6 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showResultDialog(bool isSuccess) {
|
void _showResultDialog(bool isSuccess) {
|
||||||
if (!mounted) return;
|
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
@ -180,7 +178,14 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
onPressed: _handleProfileSave,
|
onPressed: () {
|
||||||
|
if (_validateAllFields()) {
|
||||||
|
_controller.savePatientData();
|
||||||
|
_showResultDialog(true);
|
||||||
|
} else {
|
||||||
|
_showValidationErrors();
|
||||||
|
}
|
||||||
|
},
|
||||||
icon: const Icon(Icons.check, color: Colors.blue, weight: 50),
|
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';
|
_errors['address'] = 'Please complete all required address fields';
|
||||||
_hasErrors = true;
|
_hasErrors = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (address.addressType == 'Other' &&
|
||||||
|
(address.otherLabel?.isEmpty ?? true)) {
|
||||||
|
_errors['address'] = 'Please specify other address label';
|
||||||
|
_hasErrors = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return !_hasErrors;
|
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(
|
Widget _buildNavigationField(
|
||||||
String label, IconData icon, VoidCallback onTap) {
|
String label, IconData icon, VoidCallback onTap) {
|
||||||
bool isAddressField = label == 'Address';
|
bool isAddressField = label == 'Address';
|
||||||
@ -682,7 +672,8 @@ class _PatientRegistrationScreenState extends State<PatientRegistrationScreen> {
|
|||||||
|
|
||||||
return Text(
|
return Text(
|
||||||
'${address.houseNo}, ${address.line}\n'
|
'${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),
|
style: const TextStyle(color: Colors.black87),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user