fix cart order page

merge-update-with-lab-changes
Elham Rababh 4 years ago
parent a7dccb76bf
commit 7b6622ee4c

@ -128,7 +128,7 @@ class _CartOrderPageState extends State<CartOrderPage> {
GifLoaderDialogUtils.hideDialog( GifLoaderDialogUtils.hideDialog(
context); context);
}); });
})) },model: model,),)
], ],
), ),
), ),

@ -1,4 +1,6 @@
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
@ -11,8 +13,10 @@ class ProductOrderItem extends StatefulWidget {
final ShoppingCart item; final ShoppingCart item;
final VoidCallback changeCartItems; final VoidCallback changeCartItems;
final VoidCallback deleteCartItems; final VoidCallback deleteCartItems;
final OrderPreviewViewModel model;
ProductOrderItem(this.item, this.changeCartItems, this.deleteCartItems); ProductOrderItem(this.item, this.changeCartItems, this.deleteCartItems,
{this.model});
@override @override
_ProductOrderItemState createState() => _ProductOrderItemState(); _ProductOrderItemState createState() => _ProductOrderItemState();
@ -40,7 +44,8 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
leading: InkWell( leading: InkWell(
onTap: () => {widget.deleteCartItems()}, onTap: () => {widget.deleteCartItems()},
child: Icon( child: Icon(
FontAwesomeIcons.trashAlt,size: 15, FontAwesomeIcons.trashAlt,
size: 15,
color: Colors.grey.shade700, color: Colors.grey.shade700,
), ),
), ),
@ -50,17 +55,18 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
(widget.item.product.images != null && widget.item.product.images.length > 0) (widget.item.product.images != null &&
widget.item.product.images.length > 0)
? Image.network( ? Image.network(
widget.item.product.images[0].src, widget.item.product.images[0].src,
fit: BoxFit.cover, fit: BoxFit.cover,
height: 80, height: 80,
) )
: Image.asset( : Image.asset(
"assets/images/no_image.png", "assets/images/no_image.png",
fit: BoxFit.cover, fit: BoxFit.cover,
height: 80, height: 80,
), ),
Expanded( Expanded(
child: Container( child: Container(
margin: margin:
@ -101,7 +107,9 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
width: 25, width: 25,
height: 25, height: 25,
child: Icon( child: Icon(
Icons.remove, color: Colors.grey.shade400, size: 20, Icons.remove,
color: Colors.grey.shade400,
size: 20,
), ),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
@ -129,7 +137,8 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
if (value == null) { if (value == null) {
widget.item.quantity = 0; widget.item.quantity = 0;
} else { } else {
widget.item.quantity = int.parse(text); widget.item.quantity =
int.parse(text);
} }
_totalPrice = _totalPrice =
"${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}"; "${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}";
@ -144,7 +153,9 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
width: 25, width: 25,
height: 25, height: 25,
child: Icon( child: Icon(
Icons.add, color: Colors.grey.shade400, size: 20, Icons.add,
color: Colors.grey.shade400,
size: 20,
), ),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
@ -169,21 +180,21 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
widget.item.product.stockQuantity == 0 ? widget.item.product.stockQuantity == 0
Texts( ? Texts(
projectProvider.isArabic projectProvider.isArabic
? widget.item.product.stockAvailabilityn ? widget.item.product
: widget.item.product.stockAvailability, .stockAvailabilityn
fontWeight: FontWeight.normal, : widget.item.product
fontSize: 13, .stockAvailability,
color:Colors.red, fontWeight: FontWeight.normal,
fontSize: 13,
): Texts(""), color: Colors.red,
)
: Texts(""),
], ],
), ),
), ),
], ],
), ),
) )
@ -209,7 +220,7 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
_quantityOnChangeClick(Operation operation) { _quantityOnChangeClick(Operation operation) {
int newValue = 0; int newValue = 0;
setState(() { setState(() async {
switch (operation) { switch (operation) {
case Operation.inc: case Operation.inc:
{ {
@ -230,14 +241,20 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
} }
if (newValue > 0) { if (newValue > 0) {
widget.item.quantity = newValue; widget.item.quantity = newValue;
_quantityController.text = "${widget.item.quantity}"; await widget.changeCartItems();
_totalPrice = if (widget.model.state == ViewState.ErrorLocal) {
"${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}"; if (operation == Operation.dec) {
newValue = widget.item.quantity + 1;
} else {
newValue = widget.item.quantity - 1;
}
} else {
_quantityController.text = "${widget.item.quantity}";
_totalPrice =
"${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}";
}
} }
}); });
if (newValue > 0) {
widget.changeCartItems();
}
} }
@override @override

Loading…
Cancel
Save