Merge branch 'pharmacy_fix_bugs' into 'development'

pharmacy cart fixe counter

See merge request Cloud_Solution/diplomatic-quarter!470
merge-requests/473/head
Mohammad Aljammal 4 years ago
commit 8a0d0282ce

@ -32,6 +32,11 @@ class OrderPreviewViewModel extends BaseViewModel {
PaymentCheckoutData paymentCheckoutData = PaymentCheckoutData();
double totalAdditionalShippingCharge = 0;
setShoppingCartResponse(ShoppingCartResponse cart){
cartResponse = cart;
notifyListeners();
}
Future getOrderPreviewData() async {
setState(ViewState.Busy);
await _orderService.getAddresses();

@ -1,5 +1,6 @@
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart';
import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart';
@ -7,7 +8,10 @@ import 'package:diplomaticquarterapp/services/pharmacy_services/product_detail_s
import 'package:diplomaticquarterapp/models/pharmacy/specification.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/navigation_service.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../locator.dart';
@ -61,12 +65,39 @@ class ProductDetailViewModel extends BaseViewModel{
Future addToCartData(quantity, itemID) async {
hasError = false;
setState(ViewState.BusyLocal);
await _productDetailService.addToCart(quantity, itemID);
var resp = await _productDetailService.addToCart(quantity, itemID);
ShoppingCartResponse object = _handleGetShoppingCartResponse(resp);
if (_productDetailService.hasError) {
error = _productDetailService.error;
setState(ViewState.ErrorLocal);
} else
} else {
setState(ViewState.Idle);
Provider.of<OrderPreviewViewModel>(locator<NavigationService>().navigatorKey.currentContext, listen: false)
.setShoppingCartResponse( object);
}
}
ShoppingCartResponse _handleGetShoppingCartResponse(Map res) {
ShoppingCartResponse cartResponse = ShoppingCartResponse();
if (res == null) {
error = "response is null";
setState(ViewState.Error);
return null;
}
print(res);
cartResponse.itemCount = res["item_count"];
cartResponse.quantityCount = res["quantity_count"];
cartResponse.subtotal = res["subtotal"];
cartResponse.subtotalWithVat = res["subtotal_with_vat"];
cartResponse.subtotalVatAmount = res["subtotal_vat_amount"];
cartResponse.subtotalVatRate = res["subtotal_vat_rate"];
cartResponse.shoppingCarts = List();
res["shopping_carts"].forEach((item) {
ShoppingCart shoppingCart = ShoppingCart.fromJson(item);
cartResponse.shoppingCarts.add(shoppingCart);
});
return cartResponse;
}
Future addToWishlistData(itemID) async {

@ -68,10 +68,11 @@ class _Login extends State<Login> {
if(BASE_URL.contains("uat.")){
nationalIDorFile.text = "2001273";
mobileNumberController.text = mobileNo = "0555416043";
}/* else {
} else {
nationalIDorFile.text = "3376044";
mobileNumberController.text = mobileNo = "0555416575";
}*/
}
}
getDeviceToken() async {

@ -3,7 +3,7 @@ import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/compare-list.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-order-page.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-name-and-price.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/recommended_products.dart';
@ -338,6 +338,10 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
),
));
}
addToShoppingCartFunction({quantity,itemID,ProductDetailViewModel model})async{
await model.addToCartData(quantity,itemID);
}
addToWishlistFunction({itemID, ProductDetailViewModel model}) async {
isInWishList = true;
@ -353,22 +357,11 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
addToCartFunction(
{quantity,
itemID,
ProductDetailViewModel model}) async {
GifLoaderDialogUtils.showMyDialog(context);
await model.addToCartData(quantity, itemID);
GifLoaderDialogUtils.hideDialog(context);
}
addToShoppingCartFunction(
{quantity,
itemID,
ProductDetailViewModel model}) async {
ProductDetailViewModel model,
}) async {
GifLoaderDialogUtils.showMyDialog(context);
await model.addToCartData(quantity, itemID);
GifLoaderDialogUtils.hideDialog(context);
Navigator.push(
context,
FadePage(page: CartOrderPage()));
}
}

@ -25,7 +25,6 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
final bool isInWishList;
final Function addToCartFunction;
ProductAppBar(
{Key key,
this.product,
@ -33,7 +32,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
this.addToWishlistFunction,
this.quantity,
this.deleteFromWishlistFunction,
this.isInWishList, this.addToCartFunction})
this.isInWishList,
this.addToCartFunction})
: super(key: key);
AuthenticatedUserObject authenticatedUserObject =
@ -79,21 +79,34 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
builder: (context) => CartOrderPage()),
);
}),
if(Provider.of<OrderPreviewViewModel>(context, listen: false).cartResponse.quantityCount !=0)
Positioned(
top:0, right: -1.0,
child: Container(
decoration: BoxDecoration(
color: Colors.red[800],
borderRadius: BorderRadius.circular(15),
if (Provider.of<OrderPreviewViewModel>(context,
listen: false)
.cartResponse
.quantityCount !=
0)
Positioned(
top: 0,
right: -1.0,
child: Container(
decoration: BoxDecoration(
color: Colors.red[800],
borderRadius: BorderRadius.circular(15),
),
padding: EdgeInsets.only(left: 5, right: 4.5),
height: 18,
child: Center(
child: Texts(
Provider.of<OrderPreviewViewModel>(context,
listen: false)
.cartResponse
.quantityCount
.toString(),
style: "caption",
medium: true,
color: Colors.white,
)),
),
padding: EdgeInsets.only(left: 5, right: 4.5),
height: 18,
child: Center(child: Texts(Provider.of<OrderPreviewViewModel>(context, listen: false).cartResponse.quantityCount.toString(), style: "caption", medium: true, color: Colors.white,)),
),
)
)
],
),
SizedBox(
@ -138,7 +151,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
await addToCartFunction(
quantity: quantity,
itemID: itemID,
model: model);
model: model,
context: context);
Navigator.of(context).pop();
}

@ -1,13 +1,13 @@
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart';
import 'package:diplomaticquarterapp/models/pharmacy/addToCartModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/models/pharmacy/specification.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart';
class ProductDetailService extends BaseService {
bool isLogin = false;
@ -28,7 +28,6 @@ class ProductDetailService extends BaseService {
List<SpecificationModel> get productSpecification => _productSpecification;
Future getProductReviews(productID) async {
hasError = false;
await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL+productID+"?fields=reviews",
@ -74,7 +73,7 @@ class ProductDetailService extends BaseService {
}, body: request);
}
Future addToCart(quantity, itemID) async {
Future<Map> addToCart(quantity, itemID) async {
var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID);
hasError = false;
Map<String, dynamic> request;
@ -89,8 +88,7 @@ class ProductDetailService extends BaseService {
"language_id": 1
}
};
dynamic localRes;
await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false,
onSuccess: (dynamic response, int statusCode) {
@ -99,11 +97,14 @@ class ProductDetailService extends BaseService {
_addToCartModel.add(Wishlist.fromJson(item));
});
AppToast.showSuccessToast(message: 'You have added a product to the cart');
localRes = response;
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage());
}, body: request);
return Future.value(localRes);
}
Future notifyMe(customerId, itemID) async {

@ -169,7 +169,7 @@ class productTile extends StatelessWidget {
color: Colors.blue,),
onPressed: () async {
GifLoaderDialogUtils.showMyDialog(context);
await addToCartFunction(1, productID);
await addToCartFunction(1, productID, context);
GifLoaderDialogUtils.hideDialog(context);
Navigator.push(
context,
@ -317,7 +317,7 @@ class productTile extends StatelessWidget {
// await x.deletWishlistData(itemID);
// }
addToCartFunction(quantity, itemID) async {
addToCartFunction(quantity, itemID, BuildContext context) async {
ProductDetailViewModel x = new ProductDetailViewModel();
await x.addToCartData(quantity, itemID);
}

Loading…
Cancel
Save