Merge branch 'development' of https://gitlab.com/Cloud_Solution/diplomatic-quarter into merge_dev_into_dev_new_design_2.0

 Conflicts:
	lib/core/viewModels/pharmacyModule/product_detail_view_model.dart
	lib/pages/pharmacies/screens/product-details/product-detail.dart
	lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart
	lib/services/pharmacy_services/product_detail_service.dart
merge-requests/474/head
Elham Rababh 5 years ago
commit 2d687823f6

@ -31,6 +31,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';
@ -8,6 +9,10 @@ import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/navigation_service.dart';
import 'package:diplomaticquarterapp/services/pharmacy_services/product_detail_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 +66,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 {

@ -64,10 +64,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-page/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,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
final bool isInWishList;
final Function addToCartFunction;
ProductAppBar({Key key, this.product, this.model, this.addToWishlistFunction, this.quantity, this.deleteFromWishlistFunction, this.isInWishList, this.addToCartFunction}) : super(key: key);
ProductAppBar({Key key, this.product, this.model, this.addToWishlistFunction, this.quantity, this.deleteFromWishlistFunction, this.isInWishList,
this.addToCartFunction}) : super(key: key);
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
@ -130,7 +131,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
onTap: () async {
if (quantity > 0) {
{
await addToCartFunction(quantity: quantity, itemID: itemID, model: model);
await addToCartFunction(quantity: quantity, itemID: itemID, model: model,
context: context);
Navigator.of(context).pop();
}

@ -7,6 +7,7 @@ import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/specification.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart';
class ProductDetailService extends BaseService {
bool isLogin = false;
@ -27,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",
@ -73,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;
@ -88,9 +88,7 @@ class ProductDetailService extends BaseService {
"language_id": 1
}
};
dynamic localRes;
await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false,
onSuccess: (dynamic response, int statusCode) {
_addToCartModel.clear();
@ -98,11 +96,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 {

@ -163,7 +163,7 @@ class productTile extends StatelessWidget {
),
onPressed: () async {
GifLoaderDialogUtils.showMyDialog(context);
await addToCartFunction(1, productID);
await addToCartFunction(1, productID, context);
GifLoaderDialogUtils.hideDialog(context);
Navigator.push(
context,
@ -292,7 +292,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