build context handled

merge-update-with-lab-changes
taha.alam 2 years ago
parent 936682ff95
commit fe9d259cbd

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

Loading…
Cancel
Save