diff --git a/lib/widgets/patients/profile/soap_update/subjective/update_allergies_widget.dart b/lib/widgets/patients/profile/soap_update/subjective/update_allergies_widget.dart index b62bae0b..c31e8e59 100644 --- a/lib/widgets/patients/profile/soap_update/subjective/update_allergies_widget.dart +++ b/lib/widgets/patients/profile/soap_update/subjective/update_allergies_widget.dart @@ -8,10 +8,8 @@ import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/Text.dart'; import 'package:doctor_app_flutter/widgets/shared/TextFields.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; -import 'package:doctor_app_flutter/widgets/shared/dialogs/master_key_dailog.dart'; import 'package:doctor_app_flutter/widgets/shared/divider_with_spaces_around.dart'; import 'package:doctor_app_flutter/widgets/shared/master_key_checkbox_search_allergies_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart'; @@ -21,8 +19,6 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; -import '../custom_validation_error.dart'; - class UpdateAllergiesWidget extends StatefulWidget { List myAllergiesList; @@ -202,15 +198,27 @@ class _UpdateAllergiesWidgetState extends State { builder: (context) { return AddAllergies( myAllergiesList: widget.myAllergiesList, - addAllergiesFun: (List mySelectedAllergy){ - setState(() { - widget.myAllergiesList.addAll(mySelectedAllergy); + addAllergiesFun: (List mySelectedAllergy) { + bool isAllDataFilled = true; + mySelectedAllergy.forEach((element) { + if (element.selectedAllergySeverity == null) { + isAllDataFilled = false; + } + }); + if (isAllDataFilled) { + mySelectedAllergy.forEach((element) { + if (!widget.myAllergiesList.contains(element)) { + widget.myAllergiesList.add(element); + } + }); + changeParentState(); + Navigator.of(context).pop(); + } else { + helpers.showErrorToast(TranslationBase + .of(context) + .requiredMsg); + } }); - changeParentState(); - Navigator.of(context).pop(); - - } - ); }); } @@ -363,9 +371,9 @@ class _AddAllergiesState extends State { child: MasterKeyCheckboxSearchAllergiesWidget( model: model, masterList: model.allergiesList, - removeAllergy: (history){ + removeAllergy: (master) { setState(() { - // widget.allergie(history); + removeAllergyFromLocalList(master); }); }, addAllergy: (MySelectedAllergy mySelectedAllergy){ @@ -382,190 +390,6 @@ class _AddAllergiesState extends State { ), ), ), - // Container( - // height: screenSize.height * 0.070, - // child: InkWell( - // onTap: model.allergiesList != null - // ? () { - // setState(() { - // _selectedAllergy = null; - // allergyController.text = null; - // }); - // } - // : null, - // child: _selectedAllergy==null? AutoCompleteTextField( - // decoration: textFieldSelectorDecoration( - // TranslationBase - // .of(context) - // .selectAllergy, - // _selectedAllergy != null - // ? _selectedAllergy.nameEn - // : null, true, icon: EvaIcons.search), - // itemSubmitted: (item) => - // setState(() { - // _selectedAllergy = item; - // allergyController.text = - // projectViewModel.isArabic - // ? _selectedAllergy - // .nameAr - // : _selectedAllergy - // .nameEn; - // }), - // key: key, - // suggestions: model.allergiesList, - // itemBuilder: (context, suggestion) => - // new Padding( - // child: Texts( - // projectViewModel.isArabic ? suggestion - // .nameAr : suggestion.nameEn), - // padding: EdgeInsets.all(2.0)), - // itemSorter: (a, b) => 1, - // itemFilter: (suggestion, input) => - // suggestion.nameAr.toLowerCase().startsWith( - // input.toLowerCase()) || - // suggestion.nameEn.toLowerCase() - // .startsWith(input.toLowerCase()), - // ) : - // TextFields( - // onTapTextFields: model.allergiesList != null - // ? () { - // setState(() { - // _selectedAllergy = null; - // allergyController.text = null; - // }); - // } - // : null, - // hasLabelText: allergyController.text != - // '' ? true : false, - // showLabelText: true, - // hintText: TranslationBase - // .of(context) - // .selectAllergy, - // fontSize: 13.5, - // readOnly: true, - // fontWeight: FontWeight.w600, - // maxLines: 2, - // minLines: 1, - // controller: allergyController, - // suffixIcon: EvaIcons.search, - // validator: (value) { - // if (value == null) - // return TranslationBase - // .of(context) - // .emptyMessage; - // else - // return null; - // }) - // ), - // ), - // if(isFormSubmitted && _selectedAllergy == null) - // CustomValidationError(), - // SizedBox( - // height: 10, - // ), - // TextFields( - // onTapTextFields: model - // .allergySeverityList != null - // ? () { - // MasterKeyDailog dialog = MasterKeyDailog( - // list: model.allergySeverityList, - // okText: TranslationBase - // .of(context) - // .ok, - // okFunction: (selectedValue) { - // setState(() { - // _selectedAllergySeverity = - // selectedValue; - // - // severityController.text = - // projectViewModel.isArabic - // ? _selectedAllergySeverity - // .nameAr - // : _selectedAllergySeverity - // .nameEn; - // }); - // }, - // ); - // showDialog( - // barrierDismissible: false, - // context: context, - // builder: (BuildContext context) { - // return dialog; - // }, - // ); - // } - // : null, - // hasLabelText: severityController.text != - // '' ? true : false, - // showLabelText: true, - // hintText: TranslationBase - // .of(context) - // .selectSeverity, - // fontSize: 13.5, - // readOnly: true, - // // hintColor: Colors.black, - // fontWeight: FontWeight.w600, - // maxLines: 2, - // minLines: 1, - // controller: severityController, - // validator: (value) { - // if (value == null) - // return TranslationBase - // .of(context) - // .emptyMessage; - // else - // return null; - // }), SizedBox( - // height: 5, - // ), - // if(isFormSubmitted && - // _selectedAllergySeverity == null) - // CustomValidationError(), - // - // SizedBox( - // height: 10, - // ), - // Container( - // margin: EdgeInsets.only( - // left: 0, right: 0, top: 15), - // child: TextFields( - // hasLabelText: remarkController.text != ''?true:false, - // showLabelText: true, - // hintText: TranslationBase.of(context).remarks, - // fontSize: 13.5, - // // hintColor: Colors.black, - // fontWeight: FontWeight.w600, - // maxLines: 25, - // minLines: 10, - // controller: remarkController, - // validator: (value) { - // if (value == null) - // return TranslationBase - // .of(context) - // .emptyMessage; - // else - // return null; - // }), - // ), SizedBox( - // height: 10, - // ), - // AppButton( - // title: TranslationBase.of(context).add.toUpperCase(), - // onPressed: () { - // setState(() { - // isFormSubmitted = true; - // }); - // if(_selectedAllergy !=null && _selectedAllergySeverity !=null) { - // MySelectedAllergy mySelectedAllergy = new MySelectedAllergy( - // remark: remarkController.text, - // selectedAllergy: _selectedAllergy, - // isChecked: true, - // selectedAllergySeverity: _selectedAllergySeverity,); - // widget.addAllergiesFun(mySelectedAllergy); - // } - // - // }, - // ), ] ), @@ -589,6 +413,11 @@ class _AddAllergiesState extends State { return false; } + removeAllergyFromLocalList(MasterKeyModel masterKey) { + myAllergiesListLocal.removeWhere((element) => + element.selectedAllergy.id == masterKey.id); + } + MySelectedAllergy getSelectedAllergy(MasterKeyModel masterKey) { Iterable allergy = myAllergiesListLocal.where((element) => diff --git a/lib/widgets/shared/master_key_checkbox_search_allergies_widget.dart b/lib/widgets/shared/master_key_checkbox_search_allergies_widget.dart index dbc01d42..68c01d62 100644 --- a/lib/widgets/shared/master_key_checkbox_search_allergies_widget.dart +++ b/lib/widgets/shared/master_key_checkbox_search_allergies_widget.dart @@ -4,6 +4,7 @@ import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; import 'package:doctor_app_flutter/models/SOAP/my_selected_allergy.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/patients/profile/soap_update/custom_validation_error.dart'; import 'package:doctor_app_flutter/widgets/shared/TextFields.dart'; import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart'; import 'package:eva_icons_flutter/eva_icons_flutter.dart'; @@ -48,6 +49,7 @@ class _MasterKeyCheckboxSearchAllergiesWidgetState extends State { List items = List(); MasterKeyModel _selectedAllergySeverity; + bool isSubmitted = false; @override void initState() { @@ -254,9 +256,16 @@ class _MasterKeyCheckboxSearchAllergiesWidgetState SizedBox( height: 5, ), - // if(isFormSubmitted && - // _selectedAllergySeverity == null) - // CustomValidationError(), + if(isSubmitted && + mySelectedAllergy + .selectedAllergySeverity == null) + Row( + + children: [ + CustomValidationError(), + ], + mainAxisAlignment: MainAxisAlignment.start, + ), SizedBox( height: 10, @@ -318,172 +327,6 @@ class _MasterKeyCheckboxSearchAllergiesWidgetState ), ], ) - // ListView( - // children: [ - // TextFields( - // hintText: widget.hintSearchText ?? - // TranslationBase.of(context).searchHistory, - // borderWidth: 0.0, - // padding: EdgeInsets.all(20), - // borderRadius: 0, - // suffixIcon: EvaIcons.search, - // onChanged: (value) { - // filterSearchResults(value); - // }, - // ), - // // SizedBox(height: 15,), - // DividerWithSpacesAround(), - // - // - // // Container( - // // // padding:EdgeInsets.all(20), - // // child: Column( - // // children: items.map((historyInfo) { - // // return Column( - // // children: [ - // // InkWell( - // // onTap:(){ - // // - // // setState(() { - // // if (widget - // // .isServiceSelected(historyInfo)) { - // // widget.removeHistory(historyInfo); - // // } else { - // // widget.addHistory(historyInfo); - // // } - // // }); - // // }, - // // - // // child: Column( - // // children: [ - // // Row( - // // children: [ - // // Checkbox( - // // value:true, - // // // widget.isServiceSelected(historyInfo), - // // activeColor: Colors.red[800], - // // onChanged: (bool newValue) { - // // // setState(() { - // // // if (widget - // // // .isServiceSelected(historyInfo)) { - // // // widget.removeHistory(historyInfo); - // // // } else { - // // // widget.addHistory(historyInfo); - // // // } - // // // }); - // // }), - // // Expanded( - // // child: Padding( - // // padding: const EdgeInsets.symmetric( - // // horizontal: 10, vertical: 0), - // // child: AppText(projectViewModel.isArabic - // // ? historyInfo.nameAr!=""?historyInfo.nameAr:historyInfo.nameEn - // // : historyInfo.nameEn, - // // color: Color(0xFF575757), - // // fontSize: 16, - // // fontWeight:FontWeight.w600, - // // ), - // // ), - // // ), - // // ], - // // ), - // // TextFields( - // // onTapTextFields: widget.model - // // .allergySeverityList != null - // // ? () { - // // MasterKeyDailog dialog = MasterKeyDailog( - // // list: widget.model.allergySeverityList, - // // okText: TranslationBase - // // .of(context) - // // .ok, - // // okFunction: (selectedValue) { - // // // setState(() { - // // // _selectedAllergySeverity = - // // // selectedValue; - // // // - // // // severityController.text = - // // // projectViewModel.isArabic - // // // ? _selectedAllergySeverity - // // // .nameAr - // // // : _selectedAllergySeverity - // // // .nameEn; - // // // }); - // // }, - // // ); - // // showDialog( - // // barrierDismissible: false, - // // context: context, - // // builder: (BuildContext context) { - // // return dialog; - // // }, - // // ); - // // } - // // : null, - // // hasLabelText: severityController.text != - // // '' ? true : false, - // // showLabelText: true, - // // hintText: TranslationBase - // // .of(context) - // // .selectSeverity, - // // fontSize: 13.5, - // // readOnly: true, - // // // hintColor: Colors.black, - // // fontWeight: FontWeight.w600, - // // maxLines: 2, - // // minLines: 1, - // // controller: severityController, - // // validator: (value) { - // // if (value == null) - // // return TranslationBase - // // .of(context) - // // .emptyMessage; - // // else - // // return null; - // // }), SizedBox( - // // height: 5, - // // ), - // // // if(isFormSubmitted && - // // // _selectedAllergySeverity == null) - // // // CustomValidationError(), - // // - // // SizedBox( - // // height: 10, - // // ), - // // Container( - // // margin: EdgeInsets.only( - // // left: 0, right: 0, top: 15), - // // child: TextFields( - // // hasLabelText: remarkController.text != ''?true:false, - // // showLabelText: true, - // // hintText: TranslationBase.of(context).remarks, - // // fontSize: 13.5, - // // // hintColor: Colors.black, - // // fontWeight: FontWeight.w600, - // // maxLines: 25, - // // minLines: 10, - // // controller: remarkController, - // // validator: (value) { - // // if (value == null) - // // return TranslationBase - // // .of(context) - // // .emptyMessage; - // // else - // // return null; - // // }), - // // ), SizedBox( - // // height: 10, - // // ), - // // ], - // // ), - // // ), - // // // DividerWithSpacesAround(), - // // ], - // // ); - // // }).toList(), - // // ), - // // ), - // ], - // ), )), ), ), @@ -496,6 +339,9 @@ class _MasterKeyCheckboxSearchAllergiesWidgetState padding: 10, color: Color(0xFF359846), onPressed: () { + setState(() { + isSubmitted = true; + }); widget.addSelectedAllergy(); }, ),