|
|
|
|
@ -3,7 +3,6 @@ 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/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
@ -16,8 +15,8 @@ class ProductOrderItem extends StatefulWidget {
|
|
|
|
|
final VoidCallback deleteCartItems;
|
|
|
|
|
final OrderPreviewViewModel model;
|
|
|
|
|
|
|
|
|
|
ProductOrderItem(
|
|
|
|
|
this.item, this.changeCartItems, this.deleteCartItems, this.model);
|
|
|
|
|
ProductOrderItem({this.item, this.changeCartItems, this.deleteCartItems,
|
|
|
|
|
this.model});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_ProductOrderItemState createState() => _ProductOrderItemState();
|
|
|
|
|
@ -29,14 +28,15 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_quantityController.text = "${widget.item.quantity}";
|
|
|
|
|
_totalPrice =
|
|
|
|
|
"${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}";
|
|
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
_quantityController.text = "${widget.item.quantity}";
|
|
|
|
|
_totalPrice =
|
|
|
|
|
"${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}";
|
|
|
|
|
ProjectViewModel projectProvider = Provider.of(context);
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
@ -102,10 +102,8 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () => widget.model.error.isEmpty
|
|
|
|
|
? {_quantityOnChangeClick(Operation.dec)}
|
|
|
|
|
: Utils.showErrorToast(
|
|
|
|
|
widget.model.error),
|
|
|
|
|
onTap: () =>
|
|
|
|
|
{_quantityOnChangeClick(Operation.dec)},
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 25,
|
|
|
|
|
height: 25,
|
|
|
|
|
@ -150,10 +148,8 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () => widget.model.error == null
|
|
|
|
|
? {_quantityOnChangeClick(Operation.inc)}
|
|
|
|
|
: Utils.showErrorToast(
|
|
|
|
|
widget.model.error),
|
|
|
|
|
onTap: () =>
|
|
|
|
|
{_quantityOnChangeClick(Operation.inc)},
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 25,
|
|
|
|
|
height: 25,
|
|
|
|
|
@ -225,8 +221,7 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
|
|
|
|
|
|
|
|
|
|
_quantityOnChangeClick(Operation operation) {
|
|
|
|
|
int newValue = 0;
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
setState(() async {
|
|
|
|
|
switch (operation) {
|
|
|
|
|
case Operation.inc:
|
|
|
|
|
{
|
|
|
|
|
@ -247,14 +242,20 @@ class _ProductOrderItemState extends State<ProductOrderItem> {
|
|
|
|
|
}
|
|
|
|
|
if (newValue > 0) {
|
|
|
|
|
widget.item.quantity = newValue;
|
|
|
|
|
_quantityController.text = "${widget.item.quantity}";
|
|
|
|
|
_totalPrice =
|
|
|
|
|
"${(widget.item.product.price * widget.item.quantity).toStringAsFixed(2)}";
|
|
|
|
|
await widget.changeCartItems();
|
|
|
|
|
if (widget.model.state == ViewState.ErrorLocal) {
|
|
|
|
|
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
|
|
|
|
|
|