import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/order_model_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacy/order/Order.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:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:diplomaticquarterapp/widgets//pharmacy/product_tile.dart'; import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/orderDetails_service.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/order_model.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; class OrderDetailsPage extends StatefulWidget { var languageID ; OrderModel orderModel; OrderDetailsPage({ @required this.orderModel }); @override _OrderDetailsPageState createState() => _OrderDetailsPageState(); } class _OrderDetailsPageState extends State { AppSharedPreferences sharedPref = AppSharedPreferences(); String customerId=""; String page_id=""; String orderId="3516"; var model; var isCancel = false; var isRefund = false; var dataIsCancel; var dataIsRefund; @override void initState() { super.initState(); getLanguageID(); getCancelOrder(widget.orderModel.id); // cancelOrderDetail(widget.orderModel.id); } @override Widget build(BuildContext context) { return BaseView( onModelReady:(model) => model.getOrderDetails(widget.orderModel.id), builder: (_,model, wi )=> AppScaffold( appBarTitle: TranslationBase.of(context).orderDetail, isShowAppBar: true, isPharmacy:true , body: Container( color: Colors.white, child: SingleChildScrollView( child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( margin: EdgeInsets.fromLTRB(10.0, 15.0, 1.0, 5.0), child: Row( children: [ SvgPicture.asset( 'assets/images/pharmacy/shipping_mark_icon.svg', width: 28, height: 28,), Text(TranslationBase.of(context).shippingAddress, style: TextStyle(fontSize: 13.0, fontWeight: FontWeight.bold, ), ), ], ), ), Container( margin: EdgeInsets.only(top: 15.0, right: 10.0), padding: EdgeInsets.only(left: 11.0, right: 11.0), decoration: BoxDecoration( border: Border.all( color: getStatusBackgroundColor(), style: BorderStyle.solid, width: 5.0, ), color: getStatusBackgroundColor(), borderRadius: BorderRadius.circular(30.0) ), child: Text(widget.orderModel.orderStatus.toString().substring(12), // widget.languageID == "ar" // ? widget.orderModel.orderStatusn.toString() // : widget.orderModel.orderStatus.toString().substring(12) , // TranslationBase.of(context).delivered, style: TextStyle( color: Colors.white, fontSize: 13.0, fontWeight: FontWeight.bold, ), ), ), ], ), Container( margin: EdgeInsets.only(left: 10.0, top: 13.0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(model.order[0].shippingAddress.firstName.toString().substring(10) + ' ' +model.order[0].shippingAddress.lastName.toString().substring(9), style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, ), ), ] ), ), Container( margin: EdgeInsets.fromLTRB(10.0, 5.0, 1.0, 5.0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(model.order[0].shippingAddress.address1.toString().substring(9), style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, color: Colors.grey, ), ), ], ), ), Container( margin: EdgeInsets.fromLTRB(10.0, 5.0, 1.0, 5.0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(model.order[0].shippingAddress.address2.toString().substring(9), style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, color: Colors.grey, ), ), ] ), ), Container( child: Row( children: [ Container( margin: EdgeInsets.fromLTRB(10.0, 5.0, 8.0, 5.0), child: SvgPicture.asset( 'assets/images/pharmacy/mobile_number_icon.svg', height: 13,), ), Container( margin: EdgeInsets.only(top: 5.0, bottom: 5.0), child: Text(model.order[0].shippingAddress.phoneNumber.toString(), style: TextStyle(fontSize: 15.0, ), ), ), ], ), ), Divider( color: Colors.grey[350], height: 20, thickness: 1, indent: 0, endIndent: 0, ), Row( children: [ Container( margin: EdgeInsets.fromLTRB(10.0, 10.0, 5.0, 10.0), child: SvgPicture.asset( 'assets/images/pharmacy/shipping_truck_icon.svg', height: 20, width: 20,), ), Container( margin: EdgeInsets.all(10.0), child:Text(TranslationBase.of(context).shippedMethod, style: TextStyle(fontSize: 13.0, fontWeight: FontWeight.bold, ), ), ), Container( child: model.order[0].shippingRateComputationMethodSystemName == "Shipping.FixedOrByWeight" ? Container( margin: EdgeInsets.only(bottom: 10.0, top: 10.0), child: SvgPicture.asset( 'assets/images/pharmacy/hmg_shipping_logo.svg', height: 25, width: 25,), ) : Container( margin: EdgeInsets.only(bottom: 10.0, top: 10.0), child: SvgPicture.asset( 'assets/images/pharmacy/aramex_shipping_logo.svg', height: 25, width: 25,), ), ), ], ), Divider( color: Colors.grey[350], height: 20, thickness: 8, indent: 0, endIndent: 0, ), Row( children: [ Container( margin: EdgeInsets.fromLTRB(10.0, 10.0, 1.0, 10.0), child: SvgPicture.asset( 'assets/images/pharmacy/credit_card_icon.svg', height: 20, width: 20,), ), Container( margin: EdgeInsets.all(10.0), child: SvgPicture.asset( 'assets/images/pharmacy/credit_card_icon.svg', height: 20, width: 20,), ), Container( margin: EdgeInsets.only(bottom: 10.0, top: 10.0), child:Text(model.order[0].paymentName.toString().substring(12), style: TextStyle(fontSize: 13.0, fontWeight: FontWeight.bold, ), ), ), ], ), Divider( color: Colors.grey[350], height: 20, thickness: 8, indent: 0, endIndent: 0, ), Container( padding: EdgeInsets.only(bottom: 15.0), margin: EdgeInsets.only(left: 10.0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(TranslationBase.of(context).orderDetail, style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, ), ), ], ), ), ListView.builder( scrollDirection: Axis.vertical, shrinkWrap: true, physics: ScrollPhysics(), itemCount:widget.orderModel.orderItems.length, itemBuilder: (context, index){ return Container( child: productTile(productName: widget.orderModel.orderItems[index].product.name.toString(), productPrice: widget.orderModel.orderItems[index].product.price.toString(), productRate: widget.orderModel.orderItems[index].product.approvedRatingSum.toDouble(), productReviews:widget.orderModel.orderItems[index].product.approvedTotalReviews, totalPrice: widget.orderModel.orderItems[index].priceExclTax.toString(), qyt: widget.orderModel.orderItems[index].quantity.toString(),), ); } ), Container( padding: EdgeInsets.only(bottom: 10.0), margin: EdgeInsets.only(left: 10.0, top: 5.0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(TranslationBase.of(context).orderSummary, style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, ), ), ], ), ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( padding: EdgeInsets.only(bottom: 10.0), margin: EdgeInsets.only(top: 5.0, left: 10.0 ), child: Text( TranslationBase.of(context).subtotal, style: TextStyle( fontSize: 13.0, ), ), ), Container( padding: EdgeInsets.only(bottom: 10.0), margin: EdgeInsets.fromLTRB(10.0, 5.0, 5.0, 5.0), child: Row( children: [ Container( margin: EdgeInsets.only(right: 5.0), child: Text(TranslationBase.of(context).sar, style: TextStyle(fontSize: 13.0, ), ), ), Text(model.order[0].orderSubtotalExclTax.toString(), style: TextStyle(fontSize: 13.0, ), ), ], ), ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( padding: EdgeInsets.only(bottom: 10.0), margin: EdgeInsets.only(top: 5.0, left: 10.0 ), child: Text( TranslationBase.of(context).shipping, style: TextStyle( fontSize: 13.0, ), ), ), Container( padding: EdgeInsets.only(bottom: 10.0), margin: EdgeInsets.fromLTRB(10.0, 5.0, 5.0, 5.0), child: Row( children: [ Container( margin: EdgeInsets.only(right: 5.0), child: Text(TranslationBase.of(context).sar, style: TextStyle(fontSize: 13.0, ), ), ), Text(model.order[0].orderShippingExclTax.toString(), style: TextStyle(fontSize: 13.0, ), ), ], ), ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( padding: EdgeInsets.only(bottom: 10.0), margin: EdgeInsets.only(top: 5.0,left: 10.0 ), child: Text( TranslationBase.of(context).vat, style: TextStyle( fontSize: 13.0, ), ), ), Container( padding: EdgeInsets.only(bottom: 10.0), margin: EdgeInsets.fromLTRB(10.0, 5.0, 5.0, 5.0), child: Row( children: [ Container( margin: EdgeInsets.only(right: 5.0), child: Text(TranslationBase.of(context).sar, style: TextStyle(fontSize: 13.0, ), ), ), Text(model.order[0].orderTax.toString(), style: TextStyle(fontSize: 13.0, ), ), ], ), ), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( margin: EdgeInsets.only(top: 5.0,left: 10.0 ), child: Text( TranslationBase.of(context).total, style: TextStyle( fontSize: 15.0,fontWeight: FontWeight.bold, ), ), ), Container( margin: EdgeInsets.fromLTRB(10.0, 5.0, 5.0, 5.0), child: Row( children: [ Container( margin: EdgeInsets.only(right: 5.0), child: Text(TranslationBase.of(context).sar, style: TextStyle(fontSize: 15.0,fontWeight: FontWeight.bold, ), ), ), Text(model.order[0].orderTotal.toString(), style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, ), ), ], ), ), ], ), widget.orderModel.orderStatusId == 10 ? InkWell( onTap: (){ // payOnline link }, child: Container( // margin: EdgeInsets.only(top: 20.0), height: 50.0, color: Colors.transparent, child: Container( padding: EdgeInsets.only(left: 150.0, right: 150.0), decoration: BoxDecoration( border: Border.all( color: Colors.green, style: BorderStyle.solid, width: 1.0 ), color: Colors.green, borderRadius: BorderRadius.circular(5.0) ), child: Center( child: Text( TranslationBase.of(context).payOnline, style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, ), ), ), ), ), ) : Container(), // getCancelOrder(canCancel, canRefund), isCancel ? InkWell( onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) => presentConfirmDialog())); }, child: Container( // padding: EdgeInsets.only(left: 13.0, right: 13.0, top: 5.0), height: 50.0, color: Colors.transparent, child: Center( child: Text( TranslationBase.of(context).cancelOrder, style: TextStyle( color: Colors.red[900], fontWeight: FontWeight.bold, decoration: TextDecoration.underline ), ), ), ), ) : Container(), ], ), ), ), ), ); } Color getStatusBackgroundColor() { print(widget.orderModel.orderStatusId); // if(orderStatus == 'delivered') if(widget.orderModel.orderStatusId == 30 ||widget.orderModel.orderStatusId == 997 ||widget.orderModel.orderStatusId == 994) return Colors.blue[700]; else if (widget.orderModel.orderStatusId == 20 ||widget.orderModel.orderStatusId == 995 ||widget.orderModel.orderStatusId == 998 ||widget.orderModel.orderStatusId == 999) return Colors.green; else if (widget.orderModel.orderStatusId == 10) return Colors.orange[300]; else if (widget.orderModel.orderStatusId == 40 ||widget.orderModel.orderStatusId == 996 ||widget.orderModel.orderStatusId == 200) return Colors.red[900]; } getCancelOrder(dataIsCancel){ if(widget.orderModel.canCancel && widget.orderModel.canRefund) { setState(() { isCancel = true; isRefund = false; }); } else if (widget.orderModel.canCancel ){ setState(() { isCancel = true; isRefund = false; }); } else if (widget.orderModel.canRefund){ setState(() { isCancel = false; isRefund = true; }); } else { setState(() { isCancel = false; isRefund = false; }); } } presentConfirmDialog(){ ConfirmDialog dialog = new ConfirmDialog( context: context, confirmMessage: TranslationBase.of(context).confirmCancellation, okText: TranslationBase.of(context).confirm, cancelText: TranslationBase.of(context).cancel_nocaps, okFunction: () => { // cancelOrderDetail(widget.orderModel.id), ConfirmDialog.closeAlertDialog(context) }, cancelFunction: () => {}); dialog.showAlertDialog(context); } // cancelOrderDetail(order){ // if(widget.orderModel.canCancel && widget.orderModel.canRefund == false){ //// setState(() { // cancelOrderDetail(order); // AppToast.showSuccessToast(message: "Request Sent Successfully"); //// }); //// return OrderPage(); // } // else{} // } getLanguageID() async { var languageID = await sharedPref.getString(APP_LANGUAGE); setState(() { widget.languageID = languageID; }); } }