diff --git a/lib/pages/BookAppointment/components/search_by_hospital_name.dart b/lib/pages/BookAppointment/components/search_by_hospital_name.dart index 2813391b..3de28dff 100644 --- a/lib/pages/BookAppointment/components/search_by_hospital_name.dart +++ b/lib/pages/BookAppointment/components/search_by_hospital_name.dart @@ -1,6 +1,7 @@ import 'dart:collection'; import 'package:auto_size_text/auto_size_text.dart'; +import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:flutter/material.dart'; @@ -56,6 +57,8 @@ class _SearchByHospitalState extends State { @override Widget build(BuildContext context) { + AppGlobal.context = context; + return Column( children: [ Padding( @@ -66,14 +69,17 @@ class _SearchByHospitalState extends State { activeColor: CustomColors.accentColor, value: nearestAppo, onChanged: (bool? value) { - nearestAppo = value?? false; + nearestAppo = value ?? false; setState(() { }); }, ), AutoSizeText( - TranslationBase.of(context).nearestAppo.trim(), + TranslationBase + .of(context) + .nearestAppo + .trim(), maxLines: 1, minFontSize: 10, style: TextStyle( @@ -94,7 +100,7 @@ class _SearchByHospitalState extends State { decoration: containerRadius(Colors.white, 12), margin: EdgeInsets.only(left: 20, right: 20), padding: - EdgeInsets.only(left: 10, right: 10, top: 12, bottom: 12), + EdgeInsets.only(left: 10, right: 10, top: 12, bottom: 12), child: Row( children: [ Flexible( @@ -102,7 +108,9 @@ class _SearchByHospitalState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - TranslationBase.of(context).selectHospital, + TranslationBase + .of(context) + .selectHospital, style: TextStyle( fontSize: 11, letterSpacing: -0.44, @@ -115,7 +123,9 @@ class _SearchByHospitalState extends State { child: DropdownButtonHideUnderline( child: DropdownButton( hint: Text( - TranslationBase.of(context).selectHospital), + TranslationBase + .of(context) + .selectHospital), value: selectedHospital, iconSize: 0, isExpanded: true, @@ -132,7 +142,7 @@ class _SearchByHospitalState extends State { minFontSize: 10, style: TextStyle( fontSize: - SizeConfig.textMultiplier! * 1.6, + SizeConfig.textMultiplier! * 1.6, fontWeight: FontWeight.w600, letterSpacing: -0.39, height: 0.8, @@ -141,11 +151,11 @@ class _SearchByHospitalState extends State { // Text('${item.name!}'), ); }).toList(), - onChanged: (HospitalsModel? newValue) async { + onChanged: (HospitalsModel? newValue){ getClinicWrtHospital(newValue); - // setState(() { - // selectedHospital = newValue; - // }); + setState(() { + selectedHospital = newValue; + }); }, ), ), @@ -162,28 +172,29 @@ class _SearchByHospitalState extends State { onTap: () { showClickListDialog(context, clinicIds ?? List.empty(), onSelection: (ListClinicCentralized clincs) { - selectedClinic = clincs; - Navigator.pop(context); - setState(() { - dropdownTitle = clincs.clinicDescription!; - dropdownValue = clincs.clinicID.toString() + + selectedClinic = clincs; + Navigator.pop(context); + setState(() { + dropdownTitle = clincs.clinicDescription!; + dropdownValue = clincs.clinicID.toString() + "-" + clincs.isLiveCareClinicAndOnline.toString() + "-" + clincs.liveCareClinicID.toString() + "-" + - clincs.liveCareServiceID.toString(); - }); - getDoctorsList(context); - - context - .read() - .analytics - .appointment - .book_appointment_select_clinic( + clincs.liveCareServiceID.toString( + ); + }); + getDoctorsList(context); + + context + .read() + .analytics + .appointment + .book_appointment_select_clinic( appointment_type: 'regular', clinic: clincs.clinicDescription); - }); + }); }, child: Container( width: double.infinity, @@ -197,7 +208,9 @@ class _SearchByHospitalState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - TranslationBase.of(context).selectClinic, + TranslationBase + .of(context) + .selectClinic, style: TextStyle( fontSize: 11, letterSpacing: -0.44, @@ -230,7 +243,7 @@ class _SearchByHospitalState extends State { void openDropdown(GlobalKey key) { GestureDetector? detector; - detector = searchForGestureDetector(key.currentContext!); + detector = searchForGestureDetector(key.currentContext!); assert(detector != null); detector!.onTap!(); } @@ -251,7 +264,9 @@ class _SearchByHospitalState extends State { getProjectsList() { GifLoaderDialogUtils.showMyDialog(context); - int languageID = context.read().isArabic ? 1 : 2; + int languageID = context + .read() + .isArabic ? 1 : 2; ClinicListService service = new ClinicListService(); List projectsListLocal = []; service.getProjectsList(languageID, context).then((res) { @@ -275,8 +290,7 @@ class _SearchByHospitalState extends State { } - - void getClinicWrtHospital(HospitalsModel? newValue) { + void getClinicWrtHospital(HospitalsModel? newValue) async { GifLoaderDialogUtils.showMyDialog(context); ClinicListService service = new ClinicListService(); List projectsListLocal = []; @@ -284,23 +298,25 @@ class _SearchByHospitalState extends State { clinicIds = List.empty(); }); List clinicId = []; - service - .getClinicByHospital( - projectID: newValue?.mainProjectID.toString() ?? "") - .then((res) { - print("the result is obtained"); + try { + Map res = await service + .getClinicB + + yHospital( + projectID: newValue?.mainProjectID.toString() ?? ""); GifLoaderDialogUtils.hideDialog(context); if (res['MessageStatus'] == 1) { List list = res['ListClinic']; - if(list.isEmpty){ + if (list.isEmpty) { AppToast.showErrorToast(message: - TranslationBase.of(context).NoClinicFound, + TranslationBase + .of(context) + .NoClinicFound, ); - } res['ListClinic'].forEach((v) { - clinicId?.add(ListClinicCentralized.fromJson(v)); + clinicId.add(ListClinicCentralized.fromJson(v)); }); clinicIds = clinicId; setState(() { @@ -308,27 +324,67 @@ class _SearchByHospitalState extends State { }); } else { AppToast.showErrorToast(message: - TranslationBase.of(context).NoClinicFound, + TranslationBase + .of(context) + .NoClinicFound, ); } - }).catchError((err) { - print('the error is $err'); - AppToast.showErrorToast(message: - TranslationBase.of(context).NoClinicFound, - ); - GifLoaderDialogUtils.hideDialog(context); - }).catchError((err) { + } catch (e) { + print("the error is $e"); AppToast.showErrorToast(message: - TranslationBase.of(context).NoClinicFound, - ); - GifLoaderDialogUtils.hideDialog(context); + TranslationBase.of(context).NoClinicFound, + ); + GifLoaderDialogUtils.hideDialog(context); - print(err); - }); + } + + // .then((res) { + // print("the result is obtained"); + // GifLoaderDialogUtils.hideDialog(context); + // if (res['MessageStatus'] == 1) { + // List list = res['ListClinic']; + // + // if(list.isEmpty){ + // AppToast.showErrorToast(message: + // TranslationBase.of(context).NoClinicFound, + // ); + // + // } + // res['ListClinic'].forEach((v) { + // clinicId?.add(ListClinicCentralized.fromJson(v)); + // }); + // clinicIds = clinicId; + // setState(() { + // + // }); + // } else { + // AppToast.showErrorToast(message: + // TranslationBase.of(context).NoClinicFound, + // ); + // } + // }).catchError((err) { + // print('the error is $err'); + // AppToast.showErrorToast(message: + // TranslationBase.of(context).NoClinicFound, + // ); + // GifLoaderDialogUtils.hideDialog(context); + // }).catchError((err) { + // AppToast.showErrorToast(message: + // TranslationBase.of(context).NoClinicFound, + // ); + // GifLoaderDialogUtils.hideDialog(context); + // + // print(err); + // }); } - Future navigateToDentalComplaints( - BuildContext context, SearchInfo searchInfo) async { + @override + void dispose() { + super.dispose(); + } + + Future navigateToDentalComplaints(BuildContext context, + SearchInfo searchInfo) async { Navigator.push( context, FadePage( @@ -344,7 +400,9 @@ class _SearchByHospitalState extends State { } callDoctorsSearchAPI(int clinicID) { - int languageID = context.read().isArabic ? 1 : 2; + int languageID = context + .read() + .isArabic ? 1 : 2; GifLoaderDialogUtils.showMyDialog(context); List doctorsList = []; List arr = []; @@ -352,18 +410,18 @@ class _SearchByHospitalState extends State { List result; int numAll; List _patientDoctorAppointmentListHospital = - []; + []; DoctorsListService service = new DoctorsListService(); service .getDoctorsList( - clinicID, - selectedHospital?.mainProjectID.toString() != "" - ? int.parse(selectedHospital?.mainProjectID.toString() ?? "-1") - : 0, - nearestAppo, - languageID, - null) + clinicID, + selectedHospital?.mainProjectID.toString() != "" + ? int.parse(selectedHospital?.mainProjectID.toString() ?? "-1") + : 0, + nearestAppo, + languageID, + null) .then((res) { GifLoaderDialogUtils.hideDialog(context); if (res['MessageStatus'] == 1) { @@ -371,21 +429,21 @@ class _SearchByHospitalState extends State { if (res['DoctorList'].length != 0) { doctorsList.clear(); res['DoctorList'].forEach((v) { - doctorsList.add(new DoctorList.fromJson(v)); + doctorsList.add( DoctorList.fromJson(v)); }); doctorsList.forEach((element) { List doctorByHospital = - _patientDoctorAppointmentListHospital - .where( - (elementClinic) => - elementClinic.filterName == element.projectName, - ) - .toList(); + _patientDoctorAppointmentListHospital + .where( + (elementClinic) => + elementClinic.filterName == element.projectName, + ) + .toList(); if (doctorByHospital.length != 0) { _patientDoctorAppointmentListHospital[ - _patientDoctorAppointmentListHospital - .indexOf(doctorByHospital[0])] + _patientDoctorAppointmentListHospital + .indexOf(doctorByHospital[0])] .patientDoctorAppointmentList! .add(element); } else { @@ -393,7 +451,7 @@ class _SearchByHospitalState extends State { PatientDoctorAppointmentList( filterName: element.projectName, distanceInKMs: - element.projectDistanceInKiloMeters.toString(), + element.projectDistanceInKiloMeters.toString(), patientDoctorAppointment: element)); } }); @@ -414,21 +472,19 @@ class _SearchByHospitalState extends State { }); } - Future navigateToSearchResults( - context, + Future navigateToSearchResults(context, List docList, List - patientDoctorAppointmentListHospital) async { + patientDoctorAppointmentListHospital) async { Navigator.push( - context, - FadePage( - page: SearchResults( - isLiveCareAppointment: false, - doctorsList: docList, - patientDoctorAppointmentListHospital: - patientDoctorAppointmentListHospital))) + context, + FadePage( + page: SearchResults( + isLiveCareAppointment: false, + doctorsList: docList, + patientDoctorAppointmentListHospital: + patientDoctorAppointmentListHospital))) .then((value) { - print("navigation return "); dropdownValue = null; dropdownTitle = ""; @@ -466,8 +522,13 @@ class _SearchByHospitalState extends State { searchInfo.clinic = selectedClinic; searchInfo.date = DateTime.now(); - if (context.read().isLogin) { - if (context.read().user.age! > 12) { + if (context + .read() + .isLogin) { + if (context + .read() + .user + .age! > 12) { navigateToDentalComplaints(context, searchInfo); } else { callDoctorsSearchAPI(17); @@ -479,9 +540,9 @@ class _SearchByHospitalState extends State { navigateToLaserClinic(context); // callDoctorsSearchAPI(); } else if (dropdownValue!.split("-")[1] == "true" - // && authProvider.isLogin && - // authUser.patientType == 1 - ) { + // && authProvider.isLogin && + // authUser.patientType == 1 + ) { Navigator.push( context, FadePage(