fix issue in cart page

merge-update-with-lab-changes
Elham Rababh 4 years ago
parent 26c83cd93d
commit 2526d6bc6f

@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
import 'ShippingOption.dart'; import 'ShippingOption.dart';
class PaymentCheckoutData with ChangeNotifier{ class PaymentCheckoutData {
Addresses address; Addresses address;
PaymentOption paymentOption; PaymentOption paymentOption;
LacumAccountInformation lacumInformation; LacumAccountInformation lacumInformation;
@ -15,7 +15,5 @@ class PaymentCheckoutData with ChangeNotifier{
PaymentCheckoutData({this.address, this.paymentOption, this.lacumInformation, this.cartDataVisible = false, this.shippingOption, this.usedLakumPoints = 0}); PaymentCheckoutData({this.address, this.paymentOption, this.lacumInformation, this.cartDataVisible = false, this.shippingOption, this.usedLakumPoints = 0});
void updateData() {
notifyListeners();
}
} }

@ -192,7 +192,7 @@ class OrderPreviewViewModel extends BaseViewModel {
.getShippingOption(paymentCheckoutData.address) .getShippingOption(paymentCheckoutData.address)
.then((res) { .then((res) {
paymentCheckoutData.shippingOption = ShippingOption.fromJson(res); paymentCheckoutData.shippingOption = ShippingOption.fromJson(res);
paymentCheckoutData.updateData(); setState(ViewState.Idle);
}); });
if (_orderService.hasError) { if (_orderService.hasError) {
error = _orderService.error; error = _orderService.error;

@ -3,6 +3,7 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/payment-checkout-data.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/payment-checkout-data.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/order_model_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart'; import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
@ -79,20 +80,18 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> {
SizedBox( SizedBox(
height: 10, height: 10,
), ),
Consumer<PaymentCheckoutData>( model.paymentCheckoutData.lacumInformation != null
builder: (ctx, paymentData, _) => ? Container(
paymentData.lacumInformation != null child: Column(
? Container( children: [
child: Column( LakumWidget(model),
children: [ SizedBox(
LakumWidget(model), height: 10,
SizedBox( ),
height: 10, ],
), ),
], )
), : Container(),
)
: Container()),
Container( Container(
color: Colors.white, color: Colors.white,
width: double.infinity, width: double.infinity,
@ -227,7 +226,8 @@ class _OrderPreviewPageState extends State<OrderPreviewPage> {
], ],
) )
: Container(), : Container(),
) ),
SizedBox(height: model.cartResponse.shoppingCarts != null ? height * 0.10 : 0,)
], ],
), ),
), ),
@ -284,162 +284,161 @@ class _SelectAddressWidgetState extends State<SelectAddressWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Consumer<PaymentCheckoutData>( OrderPreviewViewModel model = Provider.of(context);
builder: (ctx, paymentData, _) => Container( return Container(
color: Colors.white, color: Colors.white,
child: address == null child: address == null
? InkWell( ? InkWell(
onTap: () => {_navigateToAddressPage()}, 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( child: Container(
margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), padding:
child: Row( EdgeInsets.symmetric(vertical: 0, horizontal: 6),
children: [ child: Texts(
Image.asset( TranslationBase.of(context).selectAddress,
"assets/images/pharmacy_module/ic_shipping_address.png", fontSize: 14,
width: 30.0, fontWeight: FontWeight.bold,
height: 30.0, color: Color(0xff0000ff),
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( Icon(
child: Container( Icons.arrow_forward_ios,
margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12), size: 20,
child: Column( color: Colors.grey.shade400,
crossAxisAlignment: CrossAxisAlignment.start, ),
children: [ ],
Row( ),
children: [ ),
Image.asset( )
"assets/images/pharmacy_module/ic_shipping_mark.png", : Container(
width: 30.0, child: Container(
height: 30.0, margin: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
fit: BoxFit.scaleDown, child: Column(
), crossAxisAlignment: CrossAxisAlignment.start,
Expanded( children: [
child: Container( Row(
padding: EdgeInsets.symmetric( children: [
vertical: 0, horizontal: 6), Image.asset(
child: Texts( "assets/images/pharmacy_module/ic_shipping_mark.png",
TranslationBase.of(context).shippingAddress, width: 30.0,
fontSize: 14, height: 30.0,
fontWeight: FontWeight.bold, fit: BoxFit.scaleDown,
color: Colors.black, ),
), Expanded(
), child: Container(
), padding: EdgeInsets.symmetric(
InkWell( vertical: 0, horizontal: 6),
onTap: () => {_navigateToAddressPage()}, child: Texts(
child: Texts( TranslationBase.of(context).shippingAddress,
TranslationBase.of(context).changeAddress, fontSize: 14,
fontSize: 12, fontWeight: FontWeight.bold,
fontWeight: FontWeight.normal, color: Colors.black,
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),
),
],
), ),
], ),
),
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,
), ),
), // ic_shipping_mark.png ),
), 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(
model.paymentCheckoutData.shippingOption==null?"": model.paymentCheckoutData.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
); );
} }
} }
@ -465,7 +464,6 @@ class _SelectPaymentOptionWidgetState extends State<SelectPaymentOptionWidget> {
paymentOption = result; paymentOption = result;
widget.model.paymentCheckoutData.paymentOption = widget.model.paymentCheckoutData.paymentOption =
paymentOption; paymentOption;
widget.model.paymentCheckoutData.updateData();
} }
}) })
}); });
@ -744,105 +742,103 @@ class PaymentBottomWidget extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final scaffold = Scaffold.of(context); final scaffold = Scaffold.of(context);
this.context = context; this.context = context;
OrderPreviewViewModel orderPreviewViewModel = Provider.of(context);
return Container( return Container(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 0), margin: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
child: Consumer<PaymentCheckoutData>( child: orderPreviewViewModel.paymentCheckoutData.cartDataVisible
builder: (ctx, paymentData, _) => paymentData.cartDataVisible ? Container(
? Container( child: Row(
child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
children: [ Column(
Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
children: [ Container(
Container( margin:
margin: EdgeInsets.symmetric(horizontal: 0, vertical: 4),
EdgeInsets.symmetric(horizontal: 0, vertical: 4), child: Row(
child: Row( children: [
children: [ Texts(
Texts( "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}",
"${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", fontSize: 14,
fontSize: 14, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, color: Color(0xff929295),
color: Color(0xff929295), ),
), Padding(
Padding( padding:
padding: const EdgeInsets.symmetric(horizontal: 4),
const EdgeInsets.symmetric(horizontal: 4), child: Texts(
child: Texts( "${TranslationBase.of(context).inclusiveVat}",
"${TranslationBase.of(context).inclusiveVat}", fontSize: 8,
fontSize: 8, color: Color(0xff929295),
color: Color(0xff929295), fontWeight: FontWeight.w600,
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),
), ),
), ],
], ),
), ),
) Texts(
: Container(), "${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: (orderPreviewViewModel.paymentCheckoutData.address != null &&
orderPreviewViewModel.paymentCheckoutData.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: (orderPreviewViewModel.paymentCheckoutData.address != null &&
orderPreviewViewModel.paymentCheckoutData.paymentOption != null)
? Colors.white
: Colors.grey.shade400,
fontWeight: FontWeight.bold,
fontSize: 12),
),
),
color: (orderPreviewViewModel.paymentCheckoutData.address != null &&
orderPreviewViewModel.paymentCheckoutData.paymentOption != null)
? Colors.green
: Color(0xff929295),
disabledColor: (orderPreviewViewModel.paymentCheckoutData.address != null &&
orderPreviewViewModel.paymentCheckoutData.paymentOption != null)
? Colors.green
: Color(0xff929295),
),
),
],
),
)
: Container(),
); );
} }

@ -78,6 +78,8 @@ class _PharmacyAddressesState extends State<PharmacyAddressesPage> {
}, },
), ),
), ),
SizedBox(height: height * 0.10,)
], ],
), ),
), ),

Loading…
Cancel
Save