From df7d8a8603f232db58d42da403cfc7589791ee0b Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 27 Oct 2021 13:12:42 +0300 Subject: [PATCH] Blood donation fixes --- .../medical/my_balance_view_model.dart | 2 +- lib/pages/Blood/blood_donation.dart | 157 ++++-------------- 2 files changed, 34 insertions(+), 125 deletions(-) diff --git a/lib/core/viewModels/medical/my_balance_view_model.dart b/lib/core/viewModels/medical/my_balance_view_model.dart index 9413b0ed..a92b6e16 100644 --- a/lib/core/viewModels/medical/my_balance_view_model.dart +++ b/lib/core/viewModels/medical/my_balance_view_model.dart @@ -32,7 +32,7 @@ class MyBalanceViewModel extends BaseViewModel { _bloodDonationService.CitiesModelList; BloodDetailsService _bloodDetailsService = locator(); - List get BloodDetailsModelList => + List get bloodDetailsModelList => _bloodDetailsService .BloodModelList; //_bloodDonationService.CitiesModelList; diff --git a/lib/pages/Blood/blood_donation.dart b/lib/pages/Blood/blood_donation.dart index ffb7e1ee..be58b644 100644 --- a/lib/pages/Blood/blood_donation.dart +++ b/lib/pages/Blood/blood_donation.dart @@ -1,4 +1,3 @@ -import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart'; import 'package:diplomaticquarterapp/core/model/blooddonation/blood_groub_details.dart'; @@ -14,6 +13,7 @@ import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStat import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/h2o/h20_setting.dart'; import 'package:diplomaticquarterapp/pages/Blood/user_agreement_page.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; @@ -26,10 +26,6 @@ import 'package:flutter/material.dart'; import 'package:giffy_dialog/giffy_dialog.dart'; import 'package:provider/provider.dart'; -import 'dialogs/SelectBeneficiaryDialog.dart'; -import 'dialogs/SelectPatientFamilyDialog.dart'; -import 'dialogs/SelectPatientInfoDialog.dart'; - enum BeneficiaryType { MyAccount, MyFamilyFiles, OtherAccount, NON } enum Gender { Male, Female, NON } enum Blood { Oplus, Ominus, Aplus, Aminus, Bplus, Bminus, ABplus, ABminus, NON } @@ -73,7 +69,7 @@ class _BloodDonationPageState extends State { ImagesInfo(imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/blood/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/blood/ar/0.png'), ); WidgetsBinding.instance.addPostFrameCallback((_) { - if (projectProvider.isLogin) getAuthUser(); + if (projectProvider.isLogin) authUser = projectProvider.user; }); super.initState(); } @@ -83,7 +79,10 @@ class _BloodDonationPageState extends State { projectProvider = Provider.of(context); return BaseView( - onModelReady: (model) => model.getCities(), //model.getHospitals(), + onModelReady: (model) { + model.getCities(); + model.getBlood(); + }, builder: (_, model, w) => AppScaffold( isShowAppBar: true, showNewAppBar: true, @@ -109,11 +108,11 @@ class _BloodDonationPageState extends State { SizedBox(height: 12), CommonDropDownView( TranslationBase.of(context).city, - model.CitiesModelList.isNotEmpty - ? projectProvider.isArabic + model.bloodModelList.isNotEmpty + ? model.bloodModelList[0].city + : projectProvider.isArabic ? model.CitiesModelList[_selectedHospitalIndex].descriptionN - : model.CitiesModelList[_selectedHospitalIndex].description - : "", () { + : model.CitiesModelList[_selectedHospitalIndex].description, () { List list = [ for (int i = 0; i < model.CitiesModelList.length; i++) RadioSelectionDialogModel(projectProvider.isArabic ? model.CitiesModelList[i].descriptionN : model.CitiesModelList[i].description, i), @@ -152,7 +151,7 @@ class _BloodDonationPageState extends State { ); }).withBorderedContainer, SizedBox(height: 12), - CommonDropDownView(TranslationBase.of(context).bloodType, getBlood(_selectedBloodTypeIndex), () { + CommonDropDownView(TranslationBase.of(context).bloodType, model.bloodModelList.isNotEmpty ? model.bloodModelList[0].bloodGroup : getBlood(_selectedBloodTypeIndex), () { List list = [ RadioSelectionDialogModel("O+", 0), RadioSelectionDialogModel("O-", 1), @@ -253,97 +252,34 @@ class _BloodDonationPageState extends State { ), ), ), - DefaultButton(TranslationBase.of(context).save, () async { - if (_selectedHospital == null) { - AppToast.showErrorToast(message: TranslationBase.of(context).selectCity); - return; - } - bloodDetails.city = projectProvider.isArabic ? _selectedHospital.descriptionN : _selectedHospital.description; - bloodDetails.cityCode = _selectedHospital.iD.toString(); - bloodDetails.gender = _selectedGenderIndex; - bloodDetails.bloodGroup = getBlood(_selectedBloodTypeIndex); - await model.updateBloodGroup(bloodDetails); - if (model.state == ViewState.Idle) { - AppToast.showSuccessToast(message: model.updatedRegisterBloodMessage); - } else { - AppToast.showErrorToast(message: model.error); - } - }).insideContainer + DefaultButton( + TranslationBase.of(context).save, + checkedValue + ? () async { + if (_selectedHospital == null) { + AppToast.showErrorToast(message: TranslationBase.of(context).selectCity); + return; + } + bloodDetails.city = projectProvider.isArabic ? _selectedHospital.descriptionN : _selectedHospital.description; + bloodDetails.cityCode = _selectedHospital.iD.toString(); + bloodDetails.gender = _selectedGenderIndex; + bloodDetails.bloodGroup = getBlood(_selectedBloodTypeIndex); + await model.updateBloodGroup(bloodDetails); + if (model.state == ViewState.Idle) { + AppToast.showSuccessToast(message: model.updatedRegisterBloodMessage); + } else { + AppToast.showErrorToast(message: model.error); + } + } + : null, + disabledColor: CustomColors.grey2, + ).insideContainer ], ), ), ); } - void confirmSelectBeneficiaryDialog(MyBalanceViewModel model) { - showDialog( - context: context, - child: SelectBeneficiaryDialog( - beneficiaryType: beneficiaryType, - onValueSelected: (value) { - setState(() { - if (value == BeneficiaryType.MyAccount) { - _fileTextController.text = model.user.patientID.toString(); - advanceModel.depositorName = model.user.firstName + " " + model.user.lastName; - } else - _fileTextController.text = ""; - - beneficiaryType = value; - }); - }, - ), - ); - } - - void confirmSelectPatientDialog(List patientInfoList) { - showDialog( - context: context, - child: SelectPatientInfoDialog( - patientInfoList: patientInfoList, - selectedPatientInfo: _selectedPatientInfo, - onValueSelected: (value) { - setState(() { - advanceModel.depositorName = value.fullName; - _selectedPatientInfo = value; - }); - }, - ), - ); - } - - void confirmSelectFamilyDialog(List getAllSharedRecordsByStatusList) { - showDialog( - context: context, - child: SelectPatientFamilyDialog( - getAllSharedRecordsByStatusList: getAllSharedRecordsByStatusList, - selectedPatientFamily: selectedPatientFamily, - onValueSelected: (value) { - setState(() { - selectedPatientFamily = value; - _fileTextController.text = selectedPatientFamily.patientID.toString(); - advanceModel.depositorName = value.patientName; - }); - }, - ), - ); - } - - String getBeneficiaryType() { - switch (beneficiaryType) { - case BeneficiaryType.MyAccount: - return TranslationBase.of(context).myAccount; - case BeneficiaryType.MyFamilyFiles: - return TranslationBase.of(context).myFamilyFiles; - break; - case BeneficiaryType.OtherAccount: - return TranslationBase.of(context).otherAccount; - break; - case BeneficiaryType.NON: - return TranslationBase.of(context).selectBeneficiary; - } - return TranslationBase.of(context).selectBeneficiary; - } - String getBlood(int index) { switch (index) { case 0: @@ -384,32 +320,5 @@ class _BloodDonationPageState extends State { return projectProvider.isArabic ? _selectedHospital.descriptionN : _selectedHospital.description; else return TranslationBase.of(context).selectCity; - // return List_BloodGroupDetailsModel.fromJson(0).city.toString();//"Select City";//TranslationBase.of(context).selectHospital; } - - String getPatientName() { - if (_selectedPatientInfo != null) - return _selectedPatientInfo.fullName; - else - return TranslationBase.of(context).selectPatientName; - } - - getAuthUser() async { - if (await this.sharedPref.getObject(USER_PROFILE) != null) { - var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE)); - setState(() { - authUser = data; - }); - } - } - - String getFamilyMembersName() { - if (selectedPatientFamily != null) - return selectedPatientFamily.patientName; - else - return TranslationBase.of(context).selectFamilyPatientName; - } - -//================ - }