import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart'; import 'package:diplomaticquarterapp/models/Appointments/PatientShareResposne.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:rating_bar/rating_bar.dart'; import 'package:smart_progress_bar/smart_progress_bar.dart'; import 'BookSuccess.dart'; class BookConfirm extends StatefulWidget { DoctorList doctor; String selectedDate; String selectedTime; String appoDateFormatted = ""; String appoTimeFormatted = ""; BookConfirm( {@required this.doctor, @required this.selectedDate, @required this.selectedTime}); DoctorsListService service; PatientShareResponse patientShareResponse; AuthenticatedUser authUser; @override _BookConfirmState createState() => _BookConfirmState(); } class _BookConfirmState extends State { @override void initState() { widget.authUser = new AuthenticatedUser(); getPatientData(); widget.service = new DoctorsListService(); widget.patientShareResponse = new PatientShareResponse(); super.initState(); } @override Widget build(BuildContext context) { return AppScaffold( appBarTitle: TranslationBase.of(context).bookAppo, isShowAppBar: true, body: SingleChildScrollView( child: Container( margin: EdgeInsets.all(20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( margin: EdgeInsets.only(bottom: 5.0), alignment: Alignment.center, child: Text(TranslationBase.of(context).confirmAppoHeading, textAlign: TextAlign.center, style: TextStyle( fontSize: 22.0, color: new Color(0xFF60686b), letterSpacing: 0.9))), Divider( color: Colors.grey[400], ), Container( margin: EdgeInsets.only(top: 15.0), child: Text(TranslationBase.of(context).docInfo, style: TextStyle( fontSize: 22.0, color: Colors.black, letterSpacing: 0.9))), Container( child: Card( color: Colors.white, margin: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 16.0), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), side: BorderSide(color: Colors.grey[400], width: 0.6)), child: Container( padding: EdgeInsets.all(7.0), width: MediaQuery.of(context).size.width, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ ClipRRect( borderRadius: BorderRadius.circular(100.0), child: Image.network(widget.doctor.doctorImageURL, fit: BoxFit.fill, height: 70.0, width: 70.0), ), Container( width: MediaQuery.of(context).size.width * 0.6, margin: EdgeInsets.fromLTRB(20.0, 5.0, 10.0, 5.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( widget.doctor.doctorTitle + "" + widget.doctor.name, style: TextStyle( fontSize: 14.0, color: Colors.grey[700], letterSpacing: 1.0)), Container( margin: EdgeInsets.only(top: 3.0), child: Text(widget.doctor.clinicName, style: TextStyle( fontSize: 12.0, color: Colors.grey[600], letterSpacing: 1.0)), ), Container( margin: EdgeInsets.only(top: 3.0, bottom: 3.0), child: Text( getDoctorSpeciality( widget.doctor.speciality) .trim(), style: TextStyle( fontSize: 12.0, color: Colors.grey[600], letterSpacing: 1.0)), ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisSize: MainAxisSize.max, children: [ RatingBar.readOnly( initialRating: widget .doctor.actualDoctorRate .toDouble(), size: 20.0, filledColor: Colors.yellow[700], emptyColor: Colors.grey[500], isHalfAllowed: true, halfFilledIcon: Icons.star_half, filledIcon: Icons.star, emptyIcon: Icons.star, ), ], ), ], ), ), ], ), ), ), ), Container( margin: EdgeInsets.only(top: 15.0), child: Text(TranslationBase.of(context).appoInfo, style: TextStyle( fontSize: 22.0, color: Colors.black, letterSpacing: 0.9))), Container( child: Card( color: Colors.white, margin: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 16.0), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), side: BorderSide(color: Colors.grey[400], width: 0.6)), child: Container( padding: EdgeInsets.all(7.0), width: MediaQuery.of(context).size.width, child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( margin: EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0), child: Image.asset( "assets/images/new-design/icon_hospital.png"), ), Container( margin: EdgeInsets.fromLTRB(20.0, 5.0, 10.0, 5.0), child: Text( TranslationBase.of(context).hospital + ": " + widget.doctor.projectName, style: TextStyle( fontSize: 14.0, color: Colors.grey[700], letterSpacing: 1.0)), ), ], ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( margin: EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0), child: Image.asset( "assets/images/new-design/icon_hospital.png"), ), Container( margin: EdgeInsets.fromLTRB(20.0, 5.0, 10.0, 5.0), child: Text( TranslationBase.of(context).clinic + ": " + widget.doctor.clinicName, style: TextStyle( fontSize: 14.0, color: Colors.grey[700], letterSpacing: 1.0)), ), ], ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( child: Icon( Icons.today, color: Colors.grey[700], ), ), Container( margin: EdgeInsets.fromLTRB(20.0, 5.0, 10.0, 5.0), child: Text( TranslationBase.of(context).date + ": " + getDate(), style: TextStyle( fontSize: 14.0, color: Colors.grey[700], letterSpacing: 1.0)), ), ], ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( child: Icon( Icons.timer, color: Colors.grey[700], ), ), Container( margin: EdgeInsets.fromLTRB(20.0, 5.0, 10.0, 5.0), child: Text( TranslationBase.of(context).time + ": " + widget.selectedTime, style: TextStyle( fontSize: 14.0, color: Colors.grey[700], letterSpacing: 1.0)), ), ], ), ], ), ), ), ), Container( margin: EdgeInsets.only(top: 15.0), child: Text(TranslationBase.of(context).patientInfo, style: TextStyle( fontSize: 22.0, color: Colors.black, letterSpacing: 0.9))), Container( child: Card( color: Colors.white, margin: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 16.0), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), side: BorderSide(color: Colors.grey[400], width: 0.6)), child: Container( padding: EdgeInsets.all(7.0), width: MediaQuery.of(context).size.width, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( padding: EdgeInsets.all(10.0), child: Image.asset( "assets/images/new-design/appointment_info.png", fit: BoxFit.fill, height: 60.0, width: 60.0), ), Container( width: MediaQuery.of(context).size.width * 0.6, margin: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( widget.authUser.firstName + " " + widget.authUser.lastName, style: TextStyle( fontSize: 14.0, color: Colors.grey[900], letterSpacing: 1.0)), Container( margin: EdgeInsets.only(top: 5.0), child: Text( "Gender: " + widget.authUser.genderDescription, style: TextStyle( fontSize: 12.0, color: Colors.grey[600], letterSpacing: 1.0)), ), Container( margin: EdgeInsets.only(top: 5.0, bottom: 3.0), child: Text( "Age: " + widget.authUser.age.toString(), style: TextStyle( fontSize: 12.0, color: Colors.grey[600], letterSpacing: 1.0)), ), ], ), ), ], ), ), ), ), ], ), ), ), bottomSheet: Container( width: MediaQuery.of(context).size.width, height: 50.0, margin: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 20.0), child: ButtonTheme( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), minWidth: MediaQuery.of(context).size.width * 0.7, height: 45.0, child: RaisedButton( color: new Color(0xFF60686b), textColor: Colors.white, disabledTextColor: Colors.white, disabledColor: new Color(0xFFbcc2c4), onPressed: () { insertAppointment(context, widget.doctor); }, child: Text(TranslationBase.of(context).bookNow, style: TextStyle(fontSize: 18.0)), ), ), ), ); } cancelAppointment(DoctorList docObject, AppoitmentAllHistoryResultList appo, BuildContext context) { ConfirmDialog.closeAlertDialog(context); DoctorsListService service = new DoctorsListService(); service.cancelAppointment(appo, context).then((res) { if (res['MessageStatus'] == 1) { Future.delayed(new Duration(milliseconds: 1500), () { insertAppointment(context, docObject); }); } else { AppToast.showErrorToast(message: res['ErrorEndUserMessage']); } }).catchError((err) { print(err); }).showProgressBar( text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6)); } insertAppointment(context, DoctorList docObject) { AppoitmentAllHistoryResultList appo; widget.service .insertAppointment( docObject.doctorID, docObject.clinicID, docObject.projectID, widget.selectedTime, widget.selectedDate, context) .then((res) { if (res['MessageStatus'] == 1) { AppToast.showSuccessToast(message: "Appointment Booked Successfully"); print(res['AppointmentNo']); Future.delayed(new Duration(milliseconds: 1800), () { getPatientShare(context, res['AppointmentNo'], docObject.clinicID, docObject.projectID, docObject); }); } else { appo = new AppoitmentAllHistoryResultList(); appo.appointmentNo = res['SameClinicApptList'][0]['AppointmentNo']; appo.clinicID = res['SameClinicApptList'][0]['DoctorID']; appo.projectID = res['SameClinicApptList'][0]['ProjectID']; appo.endTime = res['SameClinicApptList'][0]['EndTime']; appo.startTime = res['SameClinicApptList'][0]['StartTime']; appo.doctorID = res['SameClinicApptList'][0]['DoctorID']; appo.isLiveCareAppointment = false; appo.originalClinicID = 0; appo.originalProjectID = 0; appo.appointmentDate = res['SameClinicApptList'][0]['AppointmentDate']; ConfirmDialog dialog = new ConfirmDialog( context: context, confirmMessage: res['ErrorEndUserMessage'], okText: TranslationBase.of(context).confirm, cancelText: TranslationBase.of(context).cancel_nocaps, okFunction: () => {cancelAppointment(docObject, appo, context)}, cancelFunction: () => {}); dialog.showAlertDialog(context); } }).catchError((err) { AppToast.showErrorToast(message: err); print(err); }).showProgressBar( text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6)); } getPatientShare(context, String appointmentNo, int clinicID, int projectID, DoctorList docObject) { widget.service .getPatientShare(appointmentNo, clinicID, projectID, context) .then((res) { print(res); widget.patientShareResponse = new PatientShareResponse.fromJson(res); navigateToBookSuccess(context, docObject, widget.patientShareResponse); }).catchError((err) { print(err); }).showProgressBar( text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6)); } String getTime(DateTime dateTime) { final DateFormat formatter = DateFormat('HH:mm'); setState(() { widget.appoTimeFormatted = formatter.format(dateTime); print(widget.appoTimeFormatted); }); return widget.appoTimeFormatted; } String getDate() { var dateObj = new DateTime( int.parse(widget.selectedDate.split("-")[0]), int.parse(widget.selectedDate.split("-")[1]), int.parse(widget.selectedDate.split("-")[2]), 0, 0, 0, 0); setState(() { widget.appoDateFormatted = DateUtil.getWeekDay(dateObj.weekday) + ", " + dateObj.day.toString() + " " + DateUtil.getMonth(dateObj.month) + " " + dateObj.year.toString(); }); return widget.appoDateFormatted; } String getDoctorSpeciality(List docSpecial) { String docSpeciality = ""; docSpecial.forEach((v) { docSpeciality = docSpeciality + v + "\n"; }); return docSpeciality; } getPatientData() async { AppSharedPreferences sharedPref = AppSharedPreferences(); if (await sharedPref.getObject(USER_PROFILE) != null) { var data = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); setState(() { print(data); widget.authUser = data; }); } } Future navigateToBookSuccess(context, DoctorList docObject, PatientShareResponse patientShareResponse) async { Navigator.push( context, MaterialPageRoute( builder: (context) => BookSuccess( docObject: docObject, patientShareResponse: patientShareResponse, appoDateFormatted: widget.appoDateFormatted, appoTimeFormatted: widget.selectedTime))); } }