Merge branch 'nov_fixes' into 'development_new_design_2.0'

Nov fixes

See merge request Cloud_Solution/diplomatic-quarter!518
merge-requests/518/merge
Elham Ali 4 years ago
commit 21a684ba88

@ -91,46 +91,47 @@ class _CartOrderPageState extends State<CartOrderPage> {
endIndent: 0,
),
Container(
child: Column(
children: [
...List.generate(
model.cartResponse.shoppingCarts != null
? model.cartResponse.shoppingCarts.length
: 0,
(index) => ProductOrderItem(
model.cartResponse
.shoppingCarts[index], () async {
GifLoaderDialogUtils.showMyDialog(
context);
await model.changeProductQuantity(model
.cartResponse.shoppingCarts[index]);
if (model.state != ViewState.Error) {
// appScaffold.appBar.badgeUpdater(
// '${value.quantityCount ?? 0}');
}
if (model.state ==
ViewState.ErrorLocal) {
Utils.showErrorToast(model.error);
}
GifLoaderDialogUtils.hideDialog(
context);
}, () async {
GifLoaderDialogUtils.showMyDialog(
context);
await model
.deleteProduct(model.cartResponse
.shoppingCarts[index])
.then((value) {
if (model.state ==
ViewState.ErrorLocal) {
Utils.showErrorToast(model.error);
}
GifLoaderDialogUtils.hideDialog(
context);
});
}))
],
),
child: ListView.builder(
itemCount:
model.cartResponse.shoppingCarts.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: const AlwaysScrollableScrollPhysics (),
itemBuilder: (context, index) {
return ProductOrderItem(
item:model.cartResponse
.shoppingCarts[index],
changeCartItems:() async {
GifLoaderDialogUtils.showMyDialog(
context);
await model.changeProductQuantity(model
.cartResponse.shoppingCarts[index]);
if (model.state != ViewState.Error) {
}
if (model.state ==
ViewState.ErrorLocal) {
Utils.showErrorToast(model.error);
}
GifLoaderDialogUtils.hideDialog(
context);
},
deleteCartItems:() async {
GifLoaderDialogUtils.showMyDialog(
context);
await model
.deleteProduct(model.cartResponse
.shoppingCarts[index])
.then((value) {
if (model.state ==
ViewState.ErrorLocal) {
Utils.showErrorToast(model.error);
}
GifLoaderDialogUtils.hideDialog(
context);
});
},model: model,);
}),
),
const Divider(
color: Color(0xFFD6D6D6),

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

Loading…
Cancel
Save