fixed cart order issues

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

@ -1,47 +1,67 @@
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; 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/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/widgets/pharmacy/product_tile.dart'; import 'package:diplomaticquarterapp/widgets/pharmacy/product_tile.dart';
import 'package:flutter/material.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(); AppSharedPreferences sharedPref = AppSharedPreferences();
var languageID; var languageID;
class ProductCheckTypeWidget extends StatelessWidget {
class ProductCheckTypeWidget extends StatefulWidget {
final List<dynamic> wishlist; final List<dynamic> wishlist;
final bool isTrue; final bool isTrue;
ProductCheckTypeWidget(this.isTrue, this.wishlist); ProductCheckTypeWidget(this.isTrue, this.wishlist);
@override
_ProductCheckTypeWidgetState createState() => _ProductCheckTypeWidgetState();
}
class _ProductCheckTypeWidgetState extends State<ProductCheckTypeWidget> {
void initState() { void initState() {
getLanguageID(); getLanguageID();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return isTrue return widget.isTrue
? ListView.builder( ? ListView.builder(
itemCount: wishlist.length, itemCount: widget.wishlist.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Column( return Column(
children: [ children: [
Container( Container(
child: isTrue child: widget.isTrue
? productTile( ? productTile(
productName: languageID == 'ar' ? wishlist[index].product.namen : wishlist[index].product.name, productName: languageID == 'ar'
productPrice: wishlist[index].subtotal, ? widget.wishlist[index].product.namen
productRate: : widget.wishlist[index].product.name,
double.parse(wishlist[index].subtotalVatRate), productPrice: widget.wishlist[index].subtotal,
productImage: wishlist[index].product.images[0].src, productRate: double.parse(
showLine: isTrue, widget.wishlist[index].subtotalVatRate),
productID: wishlist[index].product.id, productImage:
widget.wishlist[index].product.images[0].src,
showLine: widget.isTrue,
productID: widget.wishlist[index].product.id,
onDelete: deleteWishListItem,
) )
: productTile( : productTile(
productName: languageID == 'ar' ? wishlist[index].product.namen : wishlist[index].product.name, productName: languageID == 'ar'
productPrice: wishlist[index].subtotal, ? widget.wishlist[index].product.namen
productRate: : widget.wishlist[index].product.name,
double.parse(wishlist[index].subtotalVatRate), productPrice: widget.wishlist[index].subtotal,
productImage: wishlist[index].product.images[0].src, productRate: double.parse(
showLine: isTrue, widget.wishlist[index].subtotalVatRate),
productImage:
widget.wishlist[index].product.images[0].src,
showLine: widget.isTrue,
onDelete: deleteWishListItem,
), ),
), ),
Divider(height: 1, color: Colors.grey) Divider(height: 1, color: Colors.grey)
@ -51,20 +71,43 @@ class ProductCheckTypeWidget extends StatelessWidget {
: GridView.count( : GridView.count(
crossAxisCount: 2, crossAxisCount: 2,
children: List.generate( children: List.generate(
wishlist.length, widget.wishlist.length,
(index) => productTile( (index) => productTile(
productName: wishlist[index].product.name, productName: widget.wishlist[index].product.name,
productPrice: wishlist[index].subtotal, productPrice: widget.wishlist[index].subtotal,
productRate: productRate:
double.parse(wishlist[index].subtotalVatRate), double.parse(widget.wishlist[index].subtotalVatRate),
productImage: wishlist[index].product.images[0].src, productImage:
showLine: isTrue, 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 { getLanguageID() async {
languageID = await sharedPref.getString(APP_LANGUAGE); languageID = await sharedPref.getString(APP_LANGUAGE);
} }

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

@ -26,7 +26,7 @@ class CartOrderPage extends StatelessWidget {
return BaseView<OrderPreviewViewModel>( return BaseView<OrderPreviewViewModel>(
onModelReady: (model){ onModelReady: (model){
model.getShoppingCart().then((value){ model.getShoppingCart().then((value){
appScaffold.appBar.badgeUpdater('${model.cartResponse.itemCount ?? 0}'); appScaffold.appBar.badgeUpdater('${model.cartResponse.quantityCount ?? 0}');
}); });
}, },
builder: (_, model, wi) => ChangeNotifierProvider.value( builder: (_, model, wi) => ChangeNotifierProvider.value(
@ -76,10 +76,10 @@ class CartOrderPage extends StatelessWidget {
cart.shoppingCarts[index], () { cart.shoppingCarts[index], () {
print(cart.shoppingCarts[index] print(cart.shoppingCarts[index]
.quantity); .quantity);
model model.changeProductQuantity(cart.shoppingCarts[index]).then((value) {
.changeProductQuantity( if (model.state != ViewState.Error) {
cart.shoppingCarts[index]) appScaffold.appBar.badgeUpdater('${value.quantityCount ?? 0}');
.then((value) { }
if (model.state == if (model.state ==
ViewState.ErrorLocal) { ViewState.ErrorLocal) {
Utils.showErrorToast( 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 int status;
final PharmacyProduct product; final PharmacyProduct product;
final dynamic productID; final dynamic productID;
final Function onDelete;
// final VoidCallback deleteWishlistItems;
productTile({ productTile(
this.productName, {this.productName,
this.productPrice, this.productPrice,
this.productRate, this.productRate,
this.productReviews, this.productReviews,
this.qyt, this.qyt,
this.totalPrice, this.totalPrice,
this.isOrderDetails = false, this.isOrderDetails = false,
this.productImage, this.productImage,
this.showLine = true, this.showLine = true,
this.img, this.img,
this.imgs, this.imgs,
this.status, this.status,
this.product, this.product,
this.productID, this.productID,
}); this.onDelete,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -136,9 +139,10 @@ class productTile extends StatelessWidget {
children: [ children: [
IconButton( IconButton(
icon: Icon(FontAwesomeIcons.trashAlt, size: 15), icon: Icon(FontAwesomeIcons.trashAlt, size: 15),
onPressed: (){ onPressed: () {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
deleteFromWishlistFunction(productID); // deleteFromWishlistFunction(productID);
onDelete(productID);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
}, },
), ),
@ -148,14 +152,13 @@ class productTile extends StatelessWidget {
IconButton( IconButton(
icon: Icon(FontAwesomeIcons.shoppingCart, size: 15), icon: Icon(FontAwesomeIcons.shoppingCart, size: 15),
onPressed: () async { onPressed: () async {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await addToCartFunction(1, productID); await addToCartFunction(1, productID);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
Navigator.push( Navigator.push(
context, context,
FadePage(page: CartOrderPage()), FadePage(page: CartOrderPage()),
); );
}, },
), ),
], ],
@ -293,10 +296,10 @@ class productTile extends StatelessWidget {
); );
} }
deleteFromWishlistFunction(itemID) async { // deleteFromWishlistFunction(itemID) async {
ProductDetailViewModel x = new ProductDetailViewModel(); // ProductDetailViewModel x = new ProductDetailViewModel();
await x.deletWishlistData(itemID); // await x.deletWishlistData(itemID);
} // }
addToCartFunction(quantity, itemID) async { addToCartFunction(quantity, itemID) async {
ProductDetailViewModel x = new ProductDetailViewModel(); ProductDetailViewModel x = new ProductDetailViewModel();

Loading…
Cancel
Save