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/pages/ToDoList/payment_method_select.dart'; import 'package:diplomaticquarterapp/routes.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/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/widgets/in_app_browser/InAppBrowser.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'QRCode.dart'; class BookSuccess extends StatefulWidget { PatientShareResponse patientShareResponse; DoctorList docObject; MyInAppBrowser browser; final ChromeSafariBrowser chromeBrowser = new MyChromeSafariBrowser(new MyInAppBrowser()); String appoDateFormatted; String appoTimeFormatted; BookSuccess( {@required this.patientShareResponse, @required this.docObject, @required this.appoDateFormatted, @required this.appoTimeFormatted}); @override _BookSuccessState createState() => _BookSuccessState(); } class _BookSuccessState extends State { AppSharedPreferences sharedPref = AppSharedPreferences(); AuthenticatedUser authUser; @override Widget build(BuildContext context) { return Scaffold( body: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( width: MediaQuery.of(context).size.width, padding: EdgeInsets.only(bottom: 10.0), color: new Color(0xFF20bc44), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( alignment: Alignment.center, margin: EdgeInsets.only(top: 40.0), child: Text(TranslationBase.of(context).bookSuccess, style: TextStyle( color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold, letterSpacing: 0.9)), ), Container( margin: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 20.0), child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( padding: EdgeInsets.all(10.0), child: Image.asset( "assets/images/new-design/check-icon.png", fit: BoxFit.fill, height: 80.0, width: 80.0), ), Container( width: MediaQuery.of(context).size.width * 0.62, margin: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Text(widget.docObject.projectName, overflow: TextOverflow.clip, style: _getTextStyling()), Container( margin: EdgeInsets.only(top: 5.0), child: Text("Insurance", style: _getTextStyling()), ), Container( margin: EdgeInsets.only(top: 5.0, bottom: 3.0), child: Text(widget.docObject.clinicName, overflow: TextOverflow.clip, style: _getTextStyling()), ), Container( margin: EdgeInsets.only(top: 5.0, bottom: 3.0), child: Text( widget.appoDateFormatted + ", " + widget.appoTimeFormatted, overflow: TextOverflow.clip, style: _getTextStyling()), ), Container( width: MediaQuery.of(context).size.width * 0.65, margin: EdgeInsets.only(top: 5.0, bottom: 3.0), child: Text( widget.docObject.doctorTitle + " " + widget.docObject.name, overflow: TextOverflow.clip, style: _getTextStyling()), ), ], ), ), ], ), ), Container( alignment: Alignment.center, decoration: BoxDecoration( border: Border.all(color: Colors.white, width: 0.5)), margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 10.0), child: Table( border: TableBorder( verticalInside: BorderSide(width: 0.5, color: Colors.white)), children: [ TableRow(children: [ TableCell( child: _getNormalText( TranslationBase.of(context).patientShare)), TableCell( child: _getNormalText(TranslationBase.of(context) .patientShareWithTax)), ]), TableRow(children: [ TableCell( child: _getHeadingText("SR " + widget.patientShareResponse.patientShare .toString())), TableCell( child: _getHeadingText("SR " + widget .patientShareResponse.patientShareWithTax .toString())), ]), ], ), ), ], ), ), getNextActionWidget(), ], ), ), bottomNavigationBar: getBottomContainer(), ); } Widget getBottomContainer() { switch (widget.patientShareResponse.nextAction) { case 0: return Container(); break; case 10: return _getConfirmAppoButtons(); break; case 15: return _getPaymentPendingAppo(); break; case 20: return _getPayNowButtons(); break; case 30: return _getQRButtons(); break; case 50: return _getConfirmAppoButtons(); break; } } Widget _getQRButtons() { return Container( alignment: Alignment.bottomCenter, height: MediaQuery.of(context).size.height * 0.18, child: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ 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: () { // navigateToQR(context); getAppoQR(context); }, child: Text(TranslationBase.of(context).viewQR.toUpperCase(), style: TextStyle(fontSize: 18.0)), ), ), ], ), ); } Widget _getPayNowButtons() { return Container( alignment: Alignment.bottomCenter, height: MediaQuery.of(context).size.height * 0.2, child: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ 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: () { startPaymentProcess(); }, child: Text(TranslationBase.of(context).payNow.toUpperCase(), style: TextStyle(fontSize: 18.0)), ), ), ButtonTheme( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), minWidth: MediaQuery.of(context).size.width * 0.7, height: 45.0, child: RaisedButton( color: new Color(0xffc5272d), textColor: Colors.white, disabledTextColor: Colors.white, disabledColor: new Color(0xFFbcc2c4), onPressed: () { navigateToHome(context); }, child: Text(TranslationBase.of(context).payLater.toUpperCase(), style: TextStyle(fontSize: 18.0)), ), ), ], ), ); } Widget _getConfirmAppoButtons() { return Container( alignment: Alignment.bottomCenter, margin: EdgeInsets.only(bottom: 5.0), height: MediaQuery.of(context).size.height * 0.15, child: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ 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: () { AppoitmentAllHistoryResultList appo = new AppoitmentAllHistoryResultList(); appo.clinicID = widget.docObject.clinicID; appo.projectID = widget.docObject.projectID; appo.appointmentNo = widget.patientShareResponse.appointmentNo; appo.serviceID = widget.patientShareResponse.serviceID; appo.isLiveCareAppointment = widget.patientShareResponse.isLiveCareAppointment; appo.doctorID = widget.patientShareResponse.doctorID; confirmAppointment(appo); }, child: Text( widget.patientShareResponse.isLiveCareAppointment ? TranslationBase.of(context) .confirmLiveCare .toUpperCase() : TranslationBase.of(context).confirm.toUpperCase(), style: TextStyle(fontSize: 18.0)), ), ), ButtonTheme( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), minWidth: MediaQuery.of(context).size.width * 0.7, height: 45.0, child: RaisedButton( color: new Color(0xFFc5272d), textColor: Colors.white, disabledTextColor: Colors.white, disabledColor: new Color(0xFFbcc2c4), onPressed: () { navigateToHome(context); }, child: Text( TranslationBase.of(context).confirmLater.toUpperCase(), style: TextStyle(fontSize: 18.0)), ), ), ], ), ); } Widget getNextActionWidget() { switch (widget.patientShareResponse.nextAction) { case 0: return Container(); break; case 10: return _getConfirmAppo(); break; case 15: return _getPaymentPendingAppo(); break; case 20: return _getPayNowAppo(); break; case 30: return _getQRAppo(); break; case 50: return _getConfirmAppo(); break; } } String getNextAction() { switch (widget.patientShareResponse.nextAction) { case 0: return 'No Action'; break; case 10: return 'Confirm'; break; case 15: return 'Payment Pending'; break; case 20: return 'Pay Now'; break; case 30: return 'QR Code'; break; case 50: return 'Confirm LiveCare'; break; } } Widget _getConfirmAppo() { return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( margin: EdgeInsets.only(top: 30.0, bottom: 40.0), alignment: Alignment.center, child: Text(TranslationBase.of(context).confirmAppo, style: TextStyle(fontSize: 18.0, letterSpacing: 0.8)), ), Flex( direction: Axis.horizontal, children: [ Expanded( child: Container( padding: EdgeInsets.only(left: 10.0), child: Row( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ _getBulletPoint("1"), Container( width: MediaQuery.of(context).size.width * 0.8, child: Text(TranslationBase.of(context).upcomingConfirm, overflow: TextOverflow.clip, style: TextStyle(fontSize: 13.0)), ), ], ), ), ), ], ), Flex( direction: Axis.horizontal, children: [ Expanded( child: Container( padding: EdgeInsets.only(top: 20.0, left: 10.0), child: Row( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ _getBulletPoint("2"), Container( width: MediaQuery.of(context).size.width * 0.8, child: Text( TranslationBase.of(context).upcomingConfirmMore, overflow: TextOverflow.clip, style: TextStyle(fontSize: 13.0)), ), ], ), ), ), ], ), Container( margin: EdgeInsets.fromLTRB(50.0, 20.0, 50.0, 20.0), child: Image.asset("assets/images/new-design/payment-method.png"), ), ], ); } Widget _getPaymentPendingAppo() { return Container(); } confirmAppointment(AppoitmentAllHistoryResultList appo) { DoctorsListService service = new DoctorsListService(); GifLoaderDialogUtils.showMyDialog(context); service .confirmAppointment(appo.appointmentNo, appo.clinicID, appo.projectID, appo.isLiveCareAppointment, context) .then((res) { GifLoaderDialogUtils.hideDialog(context); if (res['MessageStatus'] == 1) { AppToast.showSuccessToast(message: res['ErrorEndUserMessage']); if (appo.isLiveCareAppointment) { insertLiveCareVIDARequest(appo); } else { navigateToHome(context); } } else { AppToast.showErrorToast(message: res['ErrorEndUserMessage']); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } insertLiveCareVIDARequest(AppoitmentAllHistoryResultList appo) { DoctorsListService service = new DoctorsListService(); GifLoaderDialogUtils.showMyDialog(context); service .insertVIDARequest(appo.appointmentNo, appo.clinicID, appo.projectID, appo.serviceID, appo.doctorID, context) .then((res) { GifLoaderDialogUtils.hideDialog(context); if (res['MessageStatus'] == 1) { AppToast.showSuccessToast(message: res['ErrorEndUserMessage']); navigateToHome(context); } else { AppToast.showErrorToast(message: res['ErrorEndUserMessage']); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } Widget _getPayNowAppo() { return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( margin: EdgeInsets.only(top: 20.0, bottom: 0.0), alignment: Alignment.center, child: Text(TranslationBase.of(context).payNowBookSuccess, style: TextStyle( fontSize: 20.0, letterSpacing: 0.8, fontWeight: FontWeight.bold)), ), Container( alignment: Alignment.center, child: Image.asset("assets/images/new-design/no-wait-queue.png", width: 120.0, height: 120.0), ), Flex( direction: Axis.horizontal, children: [ Expanded( child: Container( padding: EdgeInsets.only(left: 10.0), child: Row( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ _getBulletPoint("1"), Container( width: MediaQuery.of(context).size.width * 0.8, child: Text( TranslationBase.of(context).payNowBookSuccesstext1, overflow: TextOverflow.fade, style: TextStyle(fontSize: 13.0)), ), ], ), ), ), ], ), Container( margin: EdgeInsets.fromLTRB(50.0, 20.0, 50.0, 20.0), child: Image.asset("assets/images/new-design/payment-method.png"), ), Flex( direction: Axis.horizontal, children: [ Expanded( child: Container( padding: EdgeInsets.only(top: 0.0, left: 10.0), child: Row( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ _getBulletPoint("2"), Container( width: MediaQuery.of(context).size.width * 0.8, child: Text( TranslationBase.of(context).payNowBookSuccesstext2, overflow: TextOverflow.clip, style: TextStyle(fontSize: 13.0)), ), ], ), ), ), ], ), ], ); } startPaymentProcess() { navigateToPaymentMethod(context, widget.patientShareResponse); } Future navigateToPaymentMethod( context, PatientShareResponse patientShareResponse) async { if (await this.sharedPref.getObject(USER_PROFILE) != null) { var data = AuthenticatedUser.fromJson( await this.sharedPref.getObject(USER_PROFILE)); setState(() { authUser = data; }); } AppoitmentAllHistoryResultList appo = new AppoitmentAllHistoryResultList(); appo.projectID = widget.patientShareResponse.projectID; appo.clinicID = widget.patientShareResponse.clinicID; appo.appointmentNo = widget.patientShareResponse.appointmentNo; Navigator.push( context, FadePage(page: PaymentMethod())) .then((value) { print(value); if (value != null) { openPayment( value, authUser, double.parse(patientShareResponse.patientShareWithTax.toString()), patientShareResponse, appo); } }); } openPayment( String paymentMethod, AuthenticatedUser authenticatedUser, double amount, PatientShareResponse patientShareResponse, AppoitmentAllHistoryResultList appo) async { if (paymentMethod == "ApplePay") { await widget.chromeBrowser.open( url: "https://applepay-datatrans-sample.herokuapp.com/", options: ChromeSafariBrowserClassOptions( android: AndroidChromeCustomTabsOptions( addDefaultShareMenuItem: false), ios: IOSSafariOptions(barCollapsingEnabled: true))); } else { widget.browser = new MyInAppBrowser( onExitCallback: onBrowserExit, appo: appo, onLoadStartCallback: onBrowserLoadStart); widget.browser.openPaymentBrowser( amount, "Appointment check in", Utils.getAppointmentTransID( appo.projectID, appo.clinicID, appo.appointmentNo), appo.projectID.toString(), authenticatedUser.emailAddress, paymentMethod, authenticatedUser.patientType, authenticatedUser.firstName, authenticatedUser.patientID, authenticatedUser, widget.browser, widget.patientShareResponse.isLiveCareAppointment, widget.patientShareResponse.appointmentDate, widget.patientShareResponse.appointmentNo, widget.patientShareResponse.clinicID, widget.patientShareResponse.doctorID); } } onBrowserLoadStart(String url) { print("onBrowserLoadStart"); print(url); MyInAppBrowser.successURLS.forEach((element) { if (url.contains(element)) { if (widget.browser.isOpened()) widget.browser.close(); MyInAppBrowser.isPaymentDone = true; return; } }); MyInAppBrowser.errorURLS.forEach((element) { if (url.contains(element)) { if (widget.browser.isOpened()) widget.browser.close(); MyInAppBrowser.isPaymentDone = false; return; } }); } onBrowserExit(AppoitmentAllHistoryResultList appo, bool isPaymentMade) { print("onBrowserExit Called!!!!"); if (isPaymentMade) checkPaymentStatus(appo); } checkPaymentStatus(AppoitmentAllHistoryResultList appo) { GifLoaderDialogUtils.showMyDialog(context); DoctorsListService service = new DoctorsListService(); service .checkPaymentStatus( Utils.getAppointmentTransID( appo.projectID, appo.clinicID, appo.appointmentNo), context) .then((res) { print("Printing Payment Status Reponse!!!!"); print(res); String paymentInfo = res['Response_Message']; if (paymentInfo == 'Success') { createAdvancePayment(res, appo); } else { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: res['Response_Message']); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } getApplePayAPQ(AppoitmentAllHistoryResultList appo) { GifLoaderDialogUtils.showMyDialog(context); DoctorsListService service = new DoctorsListService(); service .checkPaymentStatus( Utils.getAppointmentTransID( appo.projectID, appo.clinicID, appo.appointmentNo), context) .then((res) { GifLoaderDialogUtils.hideDialog(context); print("Printing Payment Status Reponse!!!!"); print(res); String paymentInfo = res['Response_Message']; if (paymentInfo == 'Success') { createAdvancePayment(res, appo); } else { AppToast.showErrorToast(message: res['Response_Message']); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } createAdvancePayment(res, AppoitmentAllHistoryResultList appo) { DoctorsListService service = new DoctorsListService(); String paymentReference = res['Fort_id'].toString(); service .createAdvancePayment(appo, appo.projectID.toString(), res['Amount'], res['Fort_id'], res['PaymentMethod'], context) .then((res) { print(res['OnlineCheckInAppointments'][0]['AdvanceNumber']); addAdvancedNumberRequest( res['OnlineCheckInAppointments'][0]['AdvanceNumber'].toString(), paymentReference, appo.appointmentNo.toString()); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } addAdvancedNumberRequest( String advanceNumber, String paymentReference, String appointmentID) { DoctorsListService service = new DoctorsListService(); service .addAdvancedNumberRequest( advanceNumber, paymentReference, appointmentID, context) .then((res) { print(res); getAppoQR(context); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } Widget _getQRAppo() { return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( margin: EdgeInsets.only(top: 30.0, bottom: 40.0), alignment: Alignment.center, child: Text(TranslationBase.of(context).noNeedToWaitInLine, style: TextStyle(fontSize: 18.0, letterSpacing: 0.8)), ), Container( alignment: Alignment.center, child: Image.asset("assets/images/new-design/device_icon.png", width: 120.0, height: 120.0), ), Flex( direction: Axis.horizontal, children: [ Expanded( child: Container( padding: EdgeInsets.only(left: 10.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( margin: EdgeInsets.only(top: 15.0), child: Row( children: [ _getBulletPoint("1"), Container( width: MediaQuery.of(context).size.width * 0.8, child: Text( TranslationBase.of(context).useQRAppoAttend, overflow: TextOverflow.fade, style: TextStyle(fontSize: 13.0)), ), ], ), ), Container( margin: EdgeInsets.only(top: 15.0), child: Row( children: [ _getBulletPoint("2"), Container( width: MediaQuery.of(context).size.width * 0.8, child: Text( TranslationBase.of(context).passQRAppoAttend, overflow: TextOverflow.fade, style: TextStyle(fontSize: 13.0)), ), ], ), ), Container( margin: EdgeInsets.only(top: 15.0), child: Row( children: [ _getBulletPoint("3"), Container( width: MediaQuery.of(context).size.width * 0.8, child: Text( TranslationBase.of(context).sitWaitingQR, overflow: TextOverflow.fade, style: TextStyle(fontSize: 13.0)), ), ], ), ), ], ), ), ), ], ), // Container( // alignment: Alignment.bottomCenter, // height: MediaQuery.of(context).size.height * 0.18, // child: Column( // mainAxisAlignment: MainAxisAlignment.end, // children: [ // 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: () { // // navigateToQR(context); // getAppoQR(context); // }, // child: Text(TranslationBase.of(context).viewQR.toUpperCase(), // style: TextStyle(fontSize: 18.0)), // ), // ), // ], // ), // ), ], ); } _getTextStyling() { return TextStyle(fontSize: 14.0, color: Colors.white, letterSpacing: 0.7); } _getBulletPoint(bulletPoint) { return Container( margin: EdgeInsets.only(left: 20.0, right: 20.0), decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.black), width: 20.0, height: 20.0, child: Center( child: Text(bulletPoint, style: TextStyle( color: Colors.white, fontSize: 12.0, )), ), ); } _getHeadingText(text) { return Container( padding: EdgeInsets.only(bottom: 10.0), child: Text(text, textAlign: TextAlign.center, style: TextStyle( fontSize: 26.0, fontFamily: 'Open-Sans', letterSpacing: 0.5, color: Colors.white))); } Future navigateToHome(context) async { Navigator.of(context).popAndPushNamed(HOME); } getAppoQR(context) { DoctorsListService service = new DoctorsListService(); service .generateAppointmentQR(widget.patientShareResponse, context) .then((res) { print(res); GifLoaderDialogUtils.hideDialog(context); navigateToQR(context, res['AppointmentQR']); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } Future navigateToQR(context, String appoQR) async { Navigator.push( context, FadePage( page: QRCode( patientShareResponse: widget.patientShareResponse, appoQR: appoQR, ))); } _getNormalText(text) { return Container( margin: EdgeInsets.only(top: 5.0), padding: EdgeInsets.only(top: 5.0, bottom: 5.0), child: Text(text, textAlign: TextAlign.center, style: TextStyle( fontSize: 12, fontFamily: 'Open-Sans', letterSpacing: 0.5, color: Colors.white)), ); } }