You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/pharmacies/screens/cart-order-preview.dart

948 lines
37 KiB
Dart

import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/payment-checkout-data.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/payment-method-select-page.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductOrderPreviewItem.dart';
import 'package:diplomaticquarterapp/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/in_app_browser/InAppBrowser.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class OrderPreviewPage extends StatelessWidget {
final List<Addresses> addresses;
OrderPreviewPage(this.addresses);
MyInAppBrowser browser;
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
final height = mediaQuery.size.height - 60 - mediaQuery.padding.top;
return BaseView<OrderPreviewViewModel>(
onModelReady: (model) => model.getShoppingCart(),
builder: (_, model, wi) => ChangeNotifierProvider.value(
value: model.paymentCheckoutData,
child: AppScaffold(
appBarTitle: "${TranslationBase.of(context).checkOut}",
isShowAppBar: true,
isPharmacy: true,
isShowDecPage: false,
backgroundColor: Colors.white,
baseViewModel: model,
body: Container(
height: height * 0.90,
child: SingleChildScrollView(
child: Container(
color: Color(0xFFF1F1F1),
child: Column(
children: [
SelectAddressWidget(model, addresses),
SizedBox(
height: 10,
),
SelectPaymentOptionWidget(model),
SizedBox(
height: 10,
),
Consumer<PaymentCheckoutData>(
builder: (ctx, paymentData, _) =>
paymentData.lacumInformation != null
? Container(
child: Column(
children: [
LakumWidget(model),
SizedBox(
height: 10,
),
],
),
)
: Container()),
Container(
color: Colors.white,
width: double.infinity,
padding: EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Texts(
TranslationBase
.of(context)
.reviewOrder,
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
...List.generate(
model.cartResponse.shoppingCarts != null
? model.cartResponse.shoppingCarts.length
: 0,
(index) =>
ProductOrderPreviewItem(
model.cartResponse
.shoppingCarts[index]),
),
],
),
),
Container(
width: double.infinity,
padding: EdgeInsets.all(8),
child: model.cartResponse.subtotal != null
? Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Texts(
TranslationBase
.of(context)
.orderSummary,
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Texts(
"${TranslationBase
.of(context)
.subtotal}",
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w500,
),
Texts(
"${TranslationBase
.of(context)
.sar} ${(model.cartResponse.subtotal)
.toStringAsFixed(2)}",
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w500,
),
],
),
const Divider(
color: Color(0xFFD6D6D6),
height: 20,
thickness: 1,
indent: 0,
endIndent: 0,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Texts(
"${TranslationBase
.of(context)
.shipping}",
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w500,
),
Texts(
"${TranslationBase
.of(context)
.sar} ${(model
.totalAdditionalShippingCharge)
.toStringAsFixed(2)}",
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w500,
),
],
),
const Divider(
color: Color(0xFFD6D6D6),
height: 20,
thickness: 1,
indent: 0,
endIndent: 0,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Texts(
"${TranslationBase
.of(context)
.vat}",
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w500,
),
Texts(
"${TranslationBase
.of(context)
.sar} ${(model.cartResponse
.subtotalVatAmount).toStringAsFixed(
2)}",
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w500,
),
],
),
const Divider(
color: Color(0xFFD6D6D6),
height: 20,
thickness: 1,
indent: 0,
endIndent: 0,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Texts(
TranslationBase
.of(context)
.total,
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.bold,
),
Texts(
"${TranslationBase
.of(context)
.sar} ${(model.cartResponse.subtotal)
.toStringAsFixed(2)}",
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.bold,
),
],
),
SizedBox(
height: 10,
),
],
)
: Container(),
)
],
),
),
),
),
bottomSheet: Container(
height: model.cartResponse.shoppingCarts != null
? height * 0.10
: 0,
color: Colors.white,
child: PaymentBottomWidget(model),
),
),
));
}
}
class SelectAddressWidget extends StatefulWidget {
final OrderPreviewViewModel model;
final List<Addresses> addresses;
SelectAddressWidget(this.model, this.addresses);
@override
_SelectAddressWidgetState createState() => _SelectAddressWidgetState();
}
class _SelectAddressWidgetState extends State<SelectAddressWidget> {
Addresses address;
_navigateToAddressPage() {
Navigator.push(context, FadePage(page: PharmacyAddressesPage()))
.then((result) {
if (result != null) {
address = result;
widget.model.paymentCheckoutData.address = address;
widget.model.getInformationsByAddress();
}
/* setState(() {
if (result != null) {
address = result;
widget.model.paymentCheckoutData.address = address;
widget.model.getInformationsByAddress();
}
})*/
});
}
@override
void initState() {
if (widget.model.paymentCheckoutData.address != null) {
address = widget.model.paymentCheckoutData.address;
}
super.initState();
}
@override
Widget build(BuildContext context) {
return Consumer<PaymentCheckoutData>(
builder: (ctx, paymentData, _) =>
Container(
color: Colors.white,
child: address == null
? InkWell(
onTap: () => {_navigateToAddressPage()},
child: Container(
margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
child: Row(
children: [
Image.asset(
"assets/images/pharmacy_module/ic_shipping_address.png",
width: 30.0,
height: 30.0,
fit: BoxFit.scaleDown,
),
Expanded(
child: Container(
padding:
EdgeInsets.symmetric(vertical: 0, horizontal: 6),
child: Texts(
TranslationBase
.of(context)
.selectAddress,
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xff0000ff),
),
),
),
Icon(
Icons.arrow_forward_ios,
size: 20,
color: Colors.grey.shade400,
),
],
),
),
)
: Container(
child: Container(
margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Image.asset(
"assets/images/pharmacy_module/ic_shipping_mark.png",
width: 30.0,
height: 30.0,
fit: BoxFit.scaleDown,
),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(
vertical: 0, horizontal: 6),
child: Texts(
TranslationBase
.of(context)
.shippingAddress,
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
InkWell(
onTap: () => {_navigateToAddressPage()},
child: Texts(
TranslationBase
.of(context)
.changeAddress,
fontSize: 12,
fontWeight: FontWeight.normal,
color: Color(0xff0000ff),
),
),
],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Texts(
"${address.firstName} ${address.lastName}",
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Texts(
"${address.address1} ${address.address2} ${address
.address2},, ${address.city}, ${address
.country} ${address.zipPostalCode}",
fontSize: 12,
fontWeight: FontWeight.normal,
color: Colors.grey.shade500,
),
),
Row(
children: [
Container(
margin: const EdgeInsets.only(right: 8),
child: Icon(
Icons.phone,
size: 20,
color: Colors.black,
),
),
Texts(
"${address.phoneNumber}",
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey,
),
],
),
Container(
margin: EdgeInsets.symmetric(vertical: 8),
child: SizedBox(
height: 2,
width: double.infinity,
child: Container(
color: Color(0xffefefef),
),
),
),
Row(
children: [
Image.asset(
"assets/images/pharmacy_module/ic_shipping_truck.png",
width: 30.0,
height: 30.0,
fit: BoxFit.scaleDown,
),
Container(
padding: EdgeInsets.symmetric(
vertical: 0, horizontal: 6),
child: Texts(
"${TranslationBase
.of(context)
.shipBy}",
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
Container(
child: Image.asset(
paymentData.shippingOption
.shippingRateComputationMethodSystemName ==
"Shipping.FixedOrByWeight"
? "assets/images/pharmacy_module/payment/hmg_shipping_logo.png"
: "assets/images/pharmacy_module/payment/aramex_shipping_logo.png",
fit: BoxFit.contain,
),
margin: EdgeInsets.symmetric(horizontal: 8),
),
],
),
],
),
),
), // ic_shipping_mark.png
),
);
}
}
class SelectPaymentOptionWidget extends StatefulWidget {
final OrderPreviewViewModel model;
SelectPaymentOptionWidget(this.model);
@override
_SelectPaymentOptionWidgetState createState() =>
_SelectPaymentOptionWidgetState();
}
class _SelectPaymentOptionWidgetState extends State<SelectPaymentOptionWidget> {
PaymentOption paymentOption;
_navigateToPaymentOption() {
Navigator.push(context, FadePage(page: PaymentMethodSelectPage()))
.then((result) =>
{
setState(() {
if (result != null) {
paymentOption = result;
widget.model.paymentCheckoutData.paymentOption =
paymentOption;
widget.model.paymentCheckoutData.updateData();
}
})
});
}
@override
void initState() {
if (widget.model.paymentCheckoutData.paymentOption != null) {
paymentOption = widget.model.paymentCheckoutData.paymentOption;
}
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: paymentOption == null
? InkWell(
onTap: () => {_navigateToPaymentOption()},
child: Container(
margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
child: Row(
children: [
Image.asset(
"assets/images/pharmacy_module/ic_payment_option.png",
width: 30.0,
height: 30.0,
fit: BoxFit.scaleDown,
),
Expanded(
child: Container(
padding:
EdgeInsets.symmetric(vertical: 0, horizontal: 6),
child: Texts(
TranslationBase
.of(context)
.selectPaymentOption,
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xff0000ff),
),
),
),
Icon(
Icons.arrow_forward_ios,
size: 20,
color: Colors.grey.shade400,
),
],
),
),
)
: Container(
margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
child: Row(
children: [
Image.asset(
"assets/images/pharmacy_module/ic_payment_option.png",
width: 30.0,
height: 30.0,
fit: BoxFit.scaleDown,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 8),
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 0),
decoration: new BoxDecoration(
color: Colors.grey.shade100,
shape: BoxShape.rectangle,
),
child: Image.asset(
widget.model.getPaymentOptionImage(paymentOption),
width: 30.0,
height: 30.0,
fit: BoxFit.scaleDown,
),
),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(vertical: 0, horizontal: 6),
child: Texts(
widget.model.getPaymentOptionName(paymentOption),
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
InkWell(
onTap: () => {_navigateToPaymentOption()},
child: Texts(
TranslationBase
.of(context)
.changeMethod,
fontSize: 12,
fontWeight: FontWeight.normal,
color: Color(0xff0000ff),
),
),
],
),
),
);
}
}
class LakumWidget extends StatefulWidget {
final OrderPreviewViewModel model;
LakumWidget(this.model);
@override
_LakumWidgetState createState() => _LakumWidgetState();
}
class _LakumWidgetState extends State<LakumWidget> {
TextEditingController _pointsController = new TextEditingController();
@override
Widget build(BuildContext context) {
ProjectViewModel projectProvider = Provider.of(context);
return Container(
color: Colors.white,
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
child: Row(
children: [
Image.asset(
"assets/images/pharmacy_module/lakum/lakum_checkout.png",
width: 30.0,
fit: BoxFit.scaleDown,
),
Container(
decoration: BoxDecoration(color: Color(0x99ffffff)),
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Texts(
"${TranslationBase
.of(context)
.lakumPoints}",
fontSize: 12,
fontWeight: FontWeight.bold,
),
Texts(
"${widget.model.paymentCheckoutData.lacumInformation
.lakumInquiryInformationObjVersion.pointsBalanceAmount}",
fontSize: 12,
fontWeight: FontWeight.normal,
),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(color: Color(0x99ffffff)),
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Texts(
"${TranslationBase
.of(context)
.riyal}",
fontSize: 12,
fontWeight: FontWeight.bold,
),
Container(
margin: projectProvider.isArabic
? EdgeInsets.only(right: 4)
: EdgeInsets.only(left: 4),
width: 60,
height: 50,
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.black, width: 0.2),
gapPadding: 0,
borderRadius: projectProvider.isArabic
? BorderRadius.only(
topRight: Radius.circular(8),
bottomRight: Radius.circular(8))
: BorderRadius.only(
topLeft: Radius.circular(8),
bottomLeft: Radius.circular(8)),
),
disabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.black, width: 0.4),
gapPadding: 0,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
bottomLeft: Radius.circular(8)),
),
),
controller: _pointsController,
keyboardType: TextInputType.number,
style: TextStyle(
fontSize: 14,
color: widget
.model
.paymentCheckoutData
.lacumInformation
.lakumInquiryInformationObjVersion
.pointsBalanceAmount >
0
? Colors.black
: Colors.grey,
),
enabled: widget
.model
.paymentCheckoutData
.lacumInformation
.lakumInquiryInformationObjVersion
.pointsBalanceAmount ==
0
? false
: true,
onChanged: (val) {
var value = int.tryParse(val);
if (value != null &&
value <=
widget
.model
.paymentCheckoutData
.lacumInformation
.lakumInquiryInformationObjVersion
.pointsBalanceAmount) {
widget.model.paymentCheckoutData.usedLakumPoints =
value;
} else {
widget.model.paymentCheckoutData.usedLakumPoints = 0;
}
_pointsController.text =
"${widget.model.paymentCheckoutData.usedLakumPoints}";
},
),
),
Container(
height: 50,
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
decoration: new BoxDecoration(
color: Color(0xff3666E0),
shape: BoxShape.rectangle,
borderRadius: projectProvider.isArabic
? BorderRadius.only(
topLeft: Radius.circular(6),
bottomLeft: Radius.circular(6))
: BorderRadius.only(
topRight: Radius.circular(6),
bottomRight: Radius.circular(6)),
border: Border.fromBorderSide(BorderSide(
color: Color(0xff3666E0),
width: 0.8,
)),
),
child: Texts(
"${TranslationBase
.of(context)
.use}",
fontSize: 12,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
);
}
}
class PaymentBottomWidget extends StatelessWidget {
final OrderPreviewViewModel model;
BuildContext context;
MyInAppBrowser browser;
PaymentBottomWidget(this.model);
@override
Widget build(BuildContext context) {
final scaffold = Scaffold.of(context);
this.context = context;
return Container(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
child: Consumer<PaymentCheckoutData>(
builder: (ctx, paymentData, _) =>
paymentData.cartDataVisible
? Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
margin:
EdgeInsets.symmetric(horizontal: 0, vertical: 4),
child: Row(
children: [
Texts(
"${TranslationBase
.of(context)
.sar} ${(model.cartResponse.subtotal)
.toStringAsFixed(2)}",
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xff929295),
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 4),
child: Texts(
"${TranslationBase
.of(context)
.inclusiveVat}",
fontSize: 8,
color: Color(0xff929295),
fontWeight: FontWeight.w600,
),
),
],
),
),
Texts(
"${model.cartResponse.quantityCount} ${TranslationBase
.of(context)
.items}",
fontSize: 10,
color: Colors.grey,
fontWeight: FontWeight.bold,
),
],
),
Container(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(
color: Color(0xff929295),
width: 1,
),
),
onPressed: (paymentData.address != null &&
paymentData.paymentOption != null)
? () async {
await model.makeOrder();
if (model.state == ViewState.Idle) {
AppToast.showSuccessToast(
message: "Order has been placed successfully!!");
openPayment(model.orderListModel[0], model.user);
} else {
AppToast.showErrorToast(message: model.error);
}
Navigator.pop(context);
Navigator.pop(context);
}
: null,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: new Text(
"${TranslationBase
.of(context)
.proceedPay}",
style: new TextStyle(
color: (paymentData.address != null &&
paymentData.paymentOption != null)
? Colors.white
: Colors.grey.shade400,
fontWeight: FontWeight.bold,
fontSize: 12),
),
),
color: (paymentData.address != null &&
paymentData.paymentOption != null)
? Colors.green
: Color(0xff929295),
disabledColor: (paymentData.address != null &&
paymentData.paymentOption != null)
? Colors.green
: Color(0xff929295),
),
),
],
),
)
: Container(),
),
);
}
openPayment(OrderDetailModel order,
AuthenticatedUser authenticatedUser,) {
browser = new MyInAppBrowser(
onExitCallback: onBrowserExit, onLoadStartCallback: onBrowserLoadStart);
browser.openPharmacyPaymentBrowser(
order,
order.orderTotal,
'ePharmacy Order',
order.id,
order.billingAddress.email,
order.customValuesXml,
"${authenticatedUser.firstName} ${authenticatedUser
.middleName} ${authenticatedUser.lastName}",
authenticatedUser.patientID,
authenticatedUser,
browser);
}
onBrowserLoadStart(String url) {
print("onBrowserLoadStart");
print(url);
MyInAppBrowser.successURLS.forEach((element) {
if (url.contains(element)) {
if (browser.isOpened()) browser.close();
MyInAppBrowser.isPaymentDone = true;
return;
}
});
MyInAppBrowser.errorURLS.forEach((element) {
if (url.contains(element)) {
if (browser.isOpened()) browser.close();
MyInAppBrowser.isPaymentDone = false;
return;
}
});
}
onBrowserExit(AppoitmentAllHistoryResultList appo, bool isPaymentMade) {
print("onBrowserExit Called!!!!");
if (isPaymentMade) {
AppToast.showSuccessToast(
message: "شكراً\nPayment status for your order is Paid");
Navigator.pop(context);
Navigator.pop(context);
} else {
AppToast.showErrorToast(
message:
"Transaction Failed!\Your transaction is field to some reason please try again or contact to the administration");
}
}
}