Skip to content

Commit

Permalink
Merge pull request #161 from codeforpakistan/v3
Browse files Browse the repository at this point in the history
removed soft wrap on title and added address fields
  • Loading branch information
mubassirhayat authored Oct 2, 2023
2 parents 03f39d9 + e602d8f commit 001bb4e
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions lib/hcai_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
helpLabelText: '',
labelText: field['label'].toString(),
value: '',
onChange: field['onChange'] ?? '',
type: field['type'] ?? '',
),
)),
}
Expand Down Expand Up @@ -588,7 +590,9 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
required String value,
required bool hasHelpLabel,
required String helpLabelText,
required bool isRequired}) {
required bool isRequired,
required String onChange,
required String type}) {
try {
if (this._values[key] == null) {
this._values[key] = value;
Expand Down Expand Up @@ -643,10 +647,15 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
popupProps: PopupProps.menu(
showSearchBox: true, isFilterOnline: true, showSelectedItems: true),
selectedItem: item,
onChanged: (v) {
onChanged: (v) async {
if (v != '') {
var newValue = options
.firstWhere((each) => each['name'] == v || each['title'] == v);
if (onChange != '' && type != '') {
final response = await this
.dynamicOnChangeRequest(onChange, newValue['name'], key);
_setAddressValues(response);
}
if (this.mounted && newValue['_id'] != null) {
setState(() => this._values[key] = newValue['_id']);
_setCompleteField(key, newValue['_id'], options, []);
Expand Down Expand Up @@ -817,8 +826,7 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
},
child: Text(
title,
overflow: TextOverflow.ellipsis,
maxLines: 1,
softWrap: true,
),
),
],
Expand All @@ -835,6 +843,13 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
);
}

_setAddressValues(data) {
if (data['district'] != null) {
this._values['patientDistrict'] = data['district']['title'];
this._values['patientProvince'] = data['province']['title'];
}
}

Widget _buildCheckbox(
{required BuildContext context,
required String title,
Expand Down Expand Up @@ -1013,6 +1028,25 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
}
}

Future<dynamic> dynamicOnChangeRequest(url, newValue, key) async {
try {
final response = await http.post(
Uri.parse(Constants.BASE_URL + '/' + url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode({key: newValue}),
);
if (response.statusCode >= 200 && response.statusCode <= 299) {
return json.decode(utf8.decode(response.bodyBytes));
}
return {};
} catch (err) {
print('error fetching adddress');
return {};
}
}

updateFormFieldsBaseOnIsSS() {
setState(() {
_selectedRole['isSSI'] = this._values['isSSI'];
Expand Down

0 comments on commit 001bb4e

Please sign in to comment.