fixed cart order issues

merge-update-with-lab-changes
Fatimah Alshammari 4 years ago
parent f09cdd944d
commit 6d72be2a73

@ -55,30 +55,30 @@ class OrderPreviewViewModel extends BaseViewModel {
}
}
Future changeProductQuantity(ShoppingCart product) async {
Future <ShoppingCartResponse> changeProductQuantity(ShoppingCart product) async {
setState(ViewState.Busy);
await _orderService.changeProductQuantity(product.id, product).then((res) {
_handleGetShoppingCartResponse(res);
});
var resp = await _orderService.changeProductQuantity(product.id, product);
var object = _handleGetShoppingCartResponse(resp);
if (_orderService.hasError) {
error = _orderService.error;
setState(ViewState.ErrorLocal);
} else {
setState(ViewState.Idle);
}
return object;
}
Future deleteProduct(ShoppingCart product) async {
Future<ShoppingCartResponse> deleteProduct(ShoppingCart product) async {
setState(ViewState.Busy);
await _orderService.deleteProduct(product.id).then((res) {
_handleGetShoppingCartResponse(res);
});
var resp = await _orderService.deleteProduct(product.id);
var object = _handleGetShoppingCartResponse(resp);
if (_orderService.hasError) {
error = _orderService.error;
setState(ViewState.Error);
} else {
setState(ViewState.Idle);
}
return object;
}
Future deleteShoppingCart() async {
@ -94,12 +94,12 @@ class OrderPreviewViewModel extends BaseViewModel {
}
}
_handleGetShoppingCartResponse(Map res) {
ShoppingCartResponse _handleGetShoppingCartResponse(Map res) {
totalAdditionalShippingCharge = 0;
if (res == null) {
error = "response is null";
setState(ViewState.Error);
return;
return null;
}
print(res);
cartResponse.itemCount = res["item_count"];
@ -115,6 +115,7 @@ class OrderPreviewViewModel extends BaseViewModel {
totalAdditionalShippingCharge += shoppingCart.product.additionalShippingCharge;
});
cartResponse.updateShoppingCard();
return cartResponse;
}
String getPaymentOptionImage(PaymentOption paymentOption) {

@ -1,47 +1,67 @@
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/wishlist.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/widgets/pharmacy/product_tile.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/wishlist_view_model.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
AppSharedPreferences sharedPref = AppSharedPreferences();
var languageID;
class ProductCheckTypeWidget extends StatelessWidget {
class ProductCheckTypeWidget extends StatefulWidget {
final List<dynamic> wishlist;
final bool isTrue;
ProductCheckTypeWidget(this.isTrue, this.wishlist);
@override
_ProductCheckTypeWidgetState createState() => _ProductCheckTypeWidgetState();
}
class _ProductCheckTypeWidgetState extends State<ProductCheckTypeWidget> {
void initState() {
getLanguageID();
}
@override
Widget build(BuildContext context) {
return isTrue
return widget.isTrue
? ListView.builder(
itemCount: wishlist.length,
itemCount: widget.wishlist.length,
itemBuilder: (BuildContext context, int index) {
return Column(
children: [
Container(
child: isTrue
child: widget.isTrue
? productTile(
productName: languageID == 'ar' ? wishlist[index].product.namen : wishlist[index].product.name,
productPrice: wishlist[index].subtotal,
productRate:
double.parse(wishlist[index].subtotalVatRate),
productImage: wishlist[index].product.images[0].src,
showLine: isTrue,
productID: wishlist[index].product.id,
productName: languageID == 'ar'
? widget.wishlist[index].product.namen
: widget.wishlist[index].product.name,
productPrice: widget.wishlist[index].subtotal,
productRate: double.parse(
widget.wishlist[index].subtotalVatRate),
productImage:
widget.wishlist[index].product.images[0].src,
showLine: widget.isTrue,
productID: widget.wishlist[index].product.id,
onDelete: deleteWishListItem,
)
: productTile(
productName: languageID == 'ar' ? wishlist[index].product.namen : wishlist[index].product.name,
productPrice: wishlist[index].subtotal,
productRate:
double.parse(wishlist[index].subtotalVatRate),
productImage: wishlist[index].product.images[0].src,
showLine: isTrue,
productName: languageID == 'ar'
? widget.wishlist[index].product.namen
: widget.wishlist[index].product.name,
productPrice: widget.wishlist[index].subtotal,
productRate: double.parse(
widget.wishlist[index].subtotalVatRate),
productImage:
widget.wishlist[index].product.images[0].src,
showLine: widget.isTrue,
onDelete: deleteWishListItem,
),
),
Divider(height: 1, color: Colors.grey)
@ -51,20 +71,43 @@ class ProductCheckTypeWidget extends StatelessWidget {
: GridView.count(
crossAxisCount: 2,
children: List.generate(
wishlist.length,
widget.wishlist.length,
(index) => productTile(
productName: wishlist[index].product.name,
productPrice: wishlist[index].subtotal,
productRate:
double.parse(wishlist[index].subtotalVatRate),
productImage: wishlist[index].product.images[0].src,
showLine: isTrue,
productName: widget.wishlist[index].product.name,
productPrice: widget.wishlist[index].subtotal,
productRate:
double.parse(widget.wishlist[index].subtotalVatRate),
productImage:
widget.wishlist[index].product.images[0].src,
showLine: widget.isTrue,
)),
);
}
deleteWishListItem(itemID) async {
ProductDetailViewModel x = new ProductDetailViewModel();
GifLoaderDialogUtils.showMyDialog(context);
await x.deletWishlistData(itemID);
setState(()
async{
await
//getWishlistData();
Navigator.push(context,
FadePage(page: WishlistPage(false)),
);
});
GifLoaderDialogUtils.hideDialog(context);
print("Delete");
}
getWishlistData() async {
WishListViewModel x = new WishListViewModel();
await x.getWishlistData();
}
}
getLanguageID() async {
languageID = await sharedPref.getString(APP_LANGUAGE);
}

@ -666,12 +666,14 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
itemBuilder: (context, index) {
return InkWell(
onTap: ()
{
Navigator.push(
async {
GifLoaderDialogUtils.showMyDialog(context);
await Navigator.push(
context,
FadePage(
page: ProductDetailPage(widget.product.id),
page: ProductDetailPage(model.recommendedProductList[index]['id']),
));
GifLoaderDialogUtils.hideDialog(context);
},
child: Card(
elevation: 2,
@ -1982,7 +1984,9 @@ class _productNameAndPriceState extends State<productNameAndPrice> {
onPressed: () async {
if (customerId != null) {
if (!isInWishlit) {
GifLoaderDialogUtils.showMyDialog(context);
await addToWishlistFunction(widget.item.id);
GifLoaderDialogUtils.hideDialog(context);
} else {
await deleteFromWishlistFunction(widget.item.id);
}

@ -26,7 +26,7 @@ class CartOrderPage extends StatelessWidget {
return BaseView<OrderPreviewViewModel>(
onModelReady: (model){
model.getShoppingCart().then((value){
appScaffold.appBar.badgeUpdater('${model.cartResponse.itemCount ?? 0}');
appScaffold.appBar.badgeUpdater('${model.cartResponse.quantityCount ?? 0}');
});
},
builder: (_, model, wi) => ChangeNotifierProvider.value(
@ -76,10 +76,10 @@ class CartOrderPage extends StatelessWidget {
cart.shoppingCarts[index], () {
print(cart.shoppingCarts[index]
.quantity);
model
.changeProductQuantity(
cart.shoppingCarts[index])
.then((value) {
model.changeProductQuantity(cart.shoppingCarts[index]).then((value) {
if (model.state != ViewState.Error) {
appScaffold.appBar.badgeUpdater('${value.quantityCount ?? 0}');
}
if (model.state ==
ViewState.ErrorLocal) {
Utils.showErrorToast(
@ -87,8 +87,13 @@ class CartOrderPage extends StatelessWidget {
}
});
},
() => model.deleteProduct(
cart.shoppingCarts[index])))
() {
model.deleteProduct(cart.shoppingCarts[index]).then((value){
if (model.state != ViewState.Error) {
appScaffold.appBar.badgeUpdater('${value.quantityCount ?? 0}');
}
});
}))
],
),
),

@ -24,23 +24,26 @@ class productTile extends StatelessWidget {
final int status;
final PharmacyProduct product;
final dynamic productID;
final Function onDelete;
// final VoidCallback deleteWishlistItems;
productTile({
this.productName,
this.productPrice,
this.productRate,
this.productReviews,
this.qyt,
this.totalPrice,
this.isOrderDetails = false,
this.productImage,
this.showLine = true,
this.img,
this.imgs,
this.status,
this.product,
this.productID,
});
productTile(
{this.productName,
this.productPrice,
this.productRate,
this.productReviews,
this.qyt,
this.totalPrice,
this.isOrderDetails = false,
this.productImage,
this.showLine = true,
this.img,
this.imgs,
this.status,
this.product,
this.productID,
this.onDelete,
});
@override
Widget build(BuildContext context) {
@ -136,9 +139,10 @@ class productTile extends StatelessWidget {
children: [
IconButton(
icon: Icon(FontAwesomeIcons.trashAlt, size: 15),
onPressed: (){
onPressed: () {
GifLoaderDialogUtils.showMyDialog(context);
deleteFromWishlistFunction(productID);
// deleteFromWishlistFunction(productID);
onDelete(productID);
GifLoaderDialogUtils.hideDialog(context);
},
),
@ -148,14 +152,13 @@ class productTile extends StatelessWidget {
IconButton(
icon: Icon(FontAwesomeIcons.shoppingCart, size: 15),
onPressed: () async {
GifLoaderDialogUtils.showMyDialog(context);
GifLoaderDialogUtils.showMyDialog(context);
await addToCartFunction(1, productID);
GifLoaderDialogUtils.hideDialog(context);
GifLoaderDialogUtils.hideDialog(context);
Navigator.push(
context,
FadePage(page: CartOrderPage()),
);
},
),
],
@ -293,10 +296,10 @@ class productTile extends StatelessWidget {
);
}
deleteFromWishlistFunction(itemID) async {
ProductDetailViewModel x = new ProductDetailViewModel();
await x.deletWishlistData(itemID);
}
// deleteFromWishlistFunction(itemID) async {
// ProductDetailViewModel x = new ProductDetailViewModel();
// await x.deletWishlistData(itemID);
// }
addToCartFunction(quantity, itemID) async {
ProductDetailViewModel x = new ProductDetailViewModel();

Loading…
Cancel
Save