import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/locator.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/pages/MyAppointments/models/AppointmentType.dart'; import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/AppointmentCardView.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/others/app_expandable_notifier.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class MyAppointments extends StatefulWidget { List appoList = []; List bookedAppoList = []; List confirmedAppoList = []; List arrivedAppoList = []; List _patientBookedAppointmentListHospital = List(); List _patientConfirmedAppointmentListHospital = List(); List _patientArrivedAppointmentListHospital = List(); @override _MyAppointmentsState createState() => _MyAppointmentsState(); } class _MyAppointmentsState extends State with SingleTickerProviderStateMixin { TabController _tabController; bool isDataLoaded = false; var sharedPref = new AppSharedPreferences(); AuthenticatedUserObject authenticatedUserObject = locator(); @override void initState() { _tabController = new TabController(length: 3, vsync: this); WidgetsBinding.instance.addPostFrameCallback((_) { if (authenticatedUserObject.isLogin) getPatientAppointmentHistory(); }); super.initState(); } @override Widget build(BuildContext context) { return AppScaffold( appBarTitle: TranslationBase.of(context).myAppointments, isShowAppBar: true, body: Container( child: Column(children: [ TabBar( tabs: [ Tab(text: TranslationBase.of(context).booked), Tab(text: TranslationBase.of(context).confirmed), Tab(text: TranslationBase.of(context).arrived), ], controller: _tabController, ), Divider( color: Colors.grey[600], thickness: 0.5, ), Expanded( child: new TabBarView( physics: NeverScrollableScrollPhysics(), children: [ isDataLoaded ? getBookedAppointments() : Container(), isDataLoaded ? getConfirmedAppointments() : Container(), isDataLoaded ? getArrivedAppointments() : Container() ], controller: _tabController, ), ), ]), ), ); } getPatientAppointmentHistory() { GifLoaderDialogUtils.showMyDialog(context); DoctorsListService service = new DoctorsListService(); widget.appoList.clear(); widget.bookedAppoList.clear(); widget.confirmedAppoList.clear(); widget.arrivedAppoList.clear(); widget._patientBookedAppointmentListHospital.clear(); widget._patientConfirmedAppointmentListHospital.clear(); widget._patientArrivedAppointmentListHospital.clear(); service.getPatientAppointmentHistory(false, context).then((res) { print(res['AppoimentAllHistoryResultList'].length); if (res['MessageStatus'] == 1) { GifLoaderDialogUtils.hideDialog(context); setState(() { if (res['AppoimentAllHistoryResultList'].length != 0) { res['AppoimentAllHistoryResultList'].forEach((v) { widget.appoList .add(new AppoitmentAllHistoryResultList.fromJson(v)); }); sortAppointmentList(); openAppointmentsTab(); isDataLoaded = true; } else {} }); } else { AppToast.showErrorToast(message: res['ErrorEndUserMessage']); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); print(err); AppToast.showErrorToast(message: err); Navigator.of(context).pop(); }); } bool isConfirmed(AppoitmentAllHistoryResultList appo) { return AppointmentType.isConfirmed(appo); } bool isArrived(AppoitmentAllHistoryResultList appo) { return AppointmentType.isArrived(appo); } bool isBooked(AppoitmentAllHistoryResultList appo) { return AppointmentType.isBooked(appo); } sortAppointmentList() { widget.appoList.forEach((v) { if (isBooked(v)) { widget.bookedAppoList.add(v); } if (isConfirmed(v)) { widget.confirmedAppoList.add(v); } if (isArrived(v)) { widget.arrivedAppoList.add(v); } }); widget.bookedAppoList.forEach((element) { List doctorByHospital = widget._patientBookedAppointmentListHospital .where( (elementClinic) => elementClinic.filterName == element.clinicName, ) .toList(); if (doctorByHospital.length != 0) { widget ._patientBookedAppointmentListHospital[widget ._patientBookedAppointmentListHospital .indexOf(doctorByHospital[0])] .patientDoctorAppointmentList .add(element); } else { widget._patientBookedAppointmentListHospital.add(PatientAppointmentList( filterName: element.clinicName, patientDoctorAppointment: element)); } }); widget.confirmedAppoList.forEach((element) { List doctorByHospital = widget._patientConfirmedAppointmentListHospital .where( (elementClinic) => elementClinic.filterName == element.clinicName, ) .toList(); if (doctorByHospital.length != 0) { widget ._patientConfirmedAppointmentListHospital[widget ._patientConfirmedAppointmentListHospital .indexOf(doctorByHospital[0])] .patientDoctorAppointmentList .add(element); } else { widget._patientConfirmedAppointmentListHospital.add( PatientAppointmentList( filterName: element.clinicName, patientDoctorAppointment: element)); } }); widget.arrivedAppoList.forEach((element) { List doctorByHospital = widget._patientArrivedAppointmentListHospital .where( (elementClinic) => elementClinic.filterName == element.clinicName, ) .toList(); if (doctorByHospital.length != 0) { widget ._patientArrivedAppointmentListHospital[widget ._patientArrivedAppointmentListHospital .indexOf(doctorByHospital[0])] .patientDoctorAppointmentList .add(element); } else { widget._patientArrivedAppointmentListHospital.add( PatientAppointmentList( filterName: element.clinicName, patientDoctorAppointment: element)); } }); } openAppointmentsTab() async { var flag = await this.sharedPref.getInt(IS_SEARCH_APPO); if (flag == 1) { _tabController.index = 0; } else if (flag == 2) { _tabController.index = 1; } else if (flag == 3) { _tabController.index = 2; } else { if (widget._patientBookedAppointmentListHospital.length != 0) { _tabController.index = 0; } else if (widget._patientConfirmedAppointmentListHospital.length != 0) { _tabController.index = 1; } else if (widget._patientArrivedAppointmentListHospital.length != 0) { _tabController.index = 2; return; } } } Widget getBookedAppointments() { return Container( child: widget.bookedAppoList.length != 0 ? new ListView.builder( itemCount: widget.bookedAppoList.length, itemBuilder: (context, i) { return AppointmentCard( appo: widget.bookedAppoList[i], onReloadAppointmentHistory: getPatientAppointmentHistory, ); }, ) : Container( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ // Image.asset( // "assets/images/new-design/noAppointmentIcon.png"), // Container( // margin: EdgeInsets.only(top: 10.0), // child: Text(TranslationBase.of(context).noBookedAppointments, // style: TextStyle( // fontSize: 16.0, // )), // ), Container( margin: EdgeInsets.only(top: 10.0), child: Container( child: widget.bookedAppoList.length != 0 ? SingleChildScrollView( physics: BouncingScrollPhysics(), child: Column( children: [ ...List.generate( widget._patientBookedAppointmentListHospital .length, (index) => AppExpandableNotifier( title: widget ._patientBookedAppointmentListHospital[ index] .filterName, bodyWidget: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: widget ._patientBookedAppointmentListHospital[ index] .patientDoctorAppointmentList .map((doctor) { return AppointmentCard( appo: doctor, onReloadAppointmentHistory: getPatientAppointmentHistory, ); }).toList(), )), ) ], ), ) : Container( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.asset( "assets/images/new-design/noAppointmentIcon.png"), Container( margin: EdgeInsets.only(top: 10.0), child: Text("No Booked Appointments", style: TextStyle( fontSize: 16.0, )), ), ], ), ), ), ), ) ], )))); } Widget getConfirmedAppointments() { return widget.confirmedAppoList.length != 0 ? Container( margin: EdgeInsets.only(top: 10.0), child: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Column( children: [ ...List.generate( widget._patientConfirmedAppointmentListHospital.length, (index) => AppExpandableNotifier( title: widget ._patientConfirmedAppointmentListHospital[index] .filterName, bodyWidget: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: widget ._patientConfirmedAppointmentListHospital[index] .patientDoctorAppointmentList .map((doctor) { return AppointmentCard( appo: doctor, onReloadAppointmentHistory: getPatientAppointmentHistory, ); }).toList(), )), ) ], ), ), ) : Container( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.asset("assets/images/new-design/noAppointmentIcon.png"), Container( margin: EdgeInsets.only(top: 10.0), child: Text( TranslationBase.of(context).noConfirmedAppointments, style: TextStyle( fontSize: 16.0, )), ), ], ), ), ); } Widget getArrivedAppointments() { return widget.arrivedAppoList.length != 0 ? Container( margin: EdgeInsets.only(top: 10.0), child: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Column( children: [ ...List.generate( widget._patientArrivedAppointmentListHospital.length, (index) => AppExpandableNotifier( title: widget ._patientArrivedAppointmentListHospital[index] .filterName, bodyWidget: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: widget ._patientArrivedAppointmentListHospital[index] .patientDoctorAppointmentList .map((doctor) { return AppointmentCard( appo: doctor, onReloadAppointmentHistory: getPatientAppointmentHistory, ); }).toList(), ), ), ) ], ), ), ) : Container( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.asset("assets/images/new-design/noAppointmentIcon.png"), Container( margin: EdgeInsets.only(top: 10.0), child: Text(TranslationBase.of(context).noArrivedAppointments, style: TextStyle( fontSize: 16.0, )), ), ], ), ), ); } }