From 6ffa07392c847de15ae38f3f05ab3abd461d2858 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 9 Nov 2021 15:36:58 +0300 Subject: [PATCH] Product detail page updates --- .../product_detail_view_model.dart | 38 ++-- lib/models/pharmacy/productDetailModel.dart | 204 ++++++++--------- .../product-details/footor/footer-widget.dart | 40 ++-- .../product-details/product-detail.dart | 8 +- .../product-name-and-price.dart | 67 ++---- .../product_detail_service.dart | 212 +++++++++--------- 6 files changed, 265 insertions(+), 304 deletions(-) diff --git a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart index 98596ee0..2ae935dd 100644 --- a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart +++ b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart @@ -1,21 +1,20 @@ import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.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'; -import 'package:diplomaticquarterapp/services/pharmacy_services/product_detail_service.dart'; import 'package:diplomaticquarterapp/models/pharmacy/specification.dart'; +import 'package:diplomaticquarterapp/services/pharmacy_services/product_detail_service.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'; -class ProductDetailViewModel extends BaseViewModel{ +class ProductDetailViewModel extends BaseViewModel { ProductDetailService _productDetailService = locator(); List get productDetailService => _productDetailService.productDetailList; @@ -28,6 +27,11 @@ class ProductDetailViewModel extends BaseViewModel{ bool hasError = false; + num get stockQuantity => _productDetailService.stockQuantity; + + String get stockAvailability => _productDetailService.stockAvailability; + + bool get isStockAvailable => _productDetailService.isStockAvailable; Future getProductReviewsData(productID) async { hasError = false; @@ -72,8 +76,7 @@ class ProductDetailViewModel extends BaseViewModel{ setState(ViewState.ErrorLocal); } else { setState(ViewState.Idle); - Provider.of(locator().navigatorKey.currentContext, listen: false) - .setShoppingCartResponse( object); + Provider.of(locator().navigatorKey.currentContext, listen: false).setShoppingCartResponse(object); } } @@ -103,11 +106,9 @@ class ProductDetailViewModel extends BaseViewModel{ Future addToWishlistData(itemID) async { hasError = false; setState(ViewState.BusyLocal); - GifLoaderDialogUtils.showMyDialog( - locator().navigatorKey.currentContext); + GifLoaderDialogUtils.showMyDialog(locator().navigatorKey.currentContext); await _productDetailService.addToWishlist(itemID); - GifLoaderDialogUtils.hideDialog( - locator().navigatorKey.currentContext); + GifLoaderDialogUtils.hideDialog(locator().navigatorKey.currentContext); if (_productDetailService.hasError) { error = _productDetailService.error; @@ -127,15 +128,12 @@ class ProductDetailViewModel extends BaseViewModel{ setState(ViewState.Idle); } - Future deleteWishlistData(itemID) async { hasError = false; setState(ViewState.BusyLocal); - GifLoaderDialogUtils.showMyDialog( - locator().navigatorKey.currentContext); + GifLoaderDialogUtils.showMyDialog(locator().navigatorKey.currentContext); await _productDetailService.deleteItemFromWishlist(itemID); - GifLoaderDialogUtils.hideDialog( - locator().navigatorKey.currentContext); + GifLoaderDialogUtils.hideDialog(locator().navigatorKey.currentContext); if (_productDetailService.hasError) { error = _productDetailService.error; @@ -144,7 +142,6 @@ class ProductDetailViewModel extends BaseViewModel{ setState(ViewState.Idle); } - Future productSpecificationData(itemID) async { hasError = false; setState(ViewState.Busy); @@ -156,10 +153,7 @@ class ProductDetailViewModel extends BaseViewModel{ setState(ViewState.Idle); } - clearReview(){ - + clearReview() { productDetailService.clear(); - } - -} \ No newline at end of file +} diff --git a/lib/models/pharmacy/productDetailModel.dart b/lib/models/pharmacy/productDetailModel.dart index d2e8f010..724f1190 100644 --- a/lib/models/pharmacy/productDetailModel.dart +++ b/lib/models/pharmacy/productDetailModel.dart @@ -1,7 +1,3 @@ -// To parse this JSON data, do -// -// final productDetail = productDetailFromJson(jsonString); - import 'dart:convert'; List productDetailFromJson(String str) => List.from(json.decode(str).map((x) => ProductDetail.fromJson(x))); @@ -16,12 +12,12 @@ class ProductDetail { List reviews; factory ProductDetail.fromJson(Map json) => ProductDetail( - reviews: List.from(json["reviews"].map((x) => Review.fromJson(x))), - ); + reviews: List.from(json["reviews"].map((x) => Review.fromJson(x))), + ); Map toJson() => { - "reviews": List.from(reviews.map((x) => x.toJson())), - }; + "reviews": List.from(reviews.map((x) => x.toJson())), + }; } class Review { @@ -62,42 +58,42 @@ class Review { dynamic product; factory Review.fromJson(Map json) => Review( - id: json["id"], - position: json["position"], - reviewId: json["review_id"], - customerId: json["customer_id"], - productId: json["product_id"], - storeId: json["store_id"], - isApproved: json["is_approved"], - title: json["title"], - reviewText: json["review_text"], - replyText: json["reply_text"], - rating: json["rating"], - helpfulYesTotal: json["helpful_yes_total"], - helpfulNoTotal: json["helpful_no_total"], - createdOnUtc: DateTime.parse(json["created_on_utc"]), - customer: Customer.fromJson(json["customer"]), - product: json["product"], - ); + id: json["id"], + position: json["position"], + reviewId: json["review_id"], + customerId: json["customer_id"], + productId: json["product_id"], + storeId: json["store_id"], + isApproved: json["is_approved"], + title: json["title"], + reviewText: json["review_text"], + replyText: json["reply_text"], + rating: json["rating"], + helpfulYesTotal: json["helpful_yes_total"], + helpfulNoTotal: json["helpful_no_total"], + createdOnUtc: DateTime.parse(json["created_on_utc"]), + customer: Customer.fromJson(json["customer"]), + product: json["product"], + ); Map toJson() => { - "id": id, - "position": position, - "review_id": reviewId, - "customer_id": customerId, - "product_id": productId, - "store_id": storeId, - "is_approved": isApproved, - "title": title, - "review_text": reviewText, - "reply_text": replyText, - "rating": rating, - "helpful_yes_total": helpfulYesTotal, - "helpful_no_total": helpfulNoTotal, - "created_on_utc": createdOnUtc.toIso8601String(), - "customer": customer.toJson(), - "product": product, - }; + "id": id, + "position": position, + "review_id": reviewId, + "customer_id": customerId, + "product_id": productId, + "store_id": storeId, + "is_approved": isApproved, + "title": title, + "review_text": reviewText, + "reply_text": replyText, + "rating": rating, + "helpful_yes_total": helpfulYesTotal, + "helpful_no_total": helpfulNoTotal, + "created_on_utc": createdOnUtc.toIso8601String(), + "customer": customer.toJson(), + "product": product, + }; } class Customer { @@ -164,75 +160,73 @@ class Customer { dynamic registeredInStoreId; factory Customer.fromJson(Map json) => Customer( - fileNumber: json["file_number"], - iqamaNumber: json["iqama_number"], - isOutSa: json["is_out_sa"], - patientType: json["patient_type"], - gender: json["gender"], - birthDate: DateTime.parse(json["birth_date"]), - phone: json["phone"], - countryCode: json["country_code"], - yahalaAccountno: json["yahala_accountno"], - billingAddress: json["billing_address"], - shippingAddress: json["shipping_address"], - id: json["id"], - username: emailValues.map[json["username"]], - email: emailValues.map[json["email"]], - firstName: json["first_name"], - lastName: json["last_name"], - languageId: json["language_id"], - adminComment: json["admin_comment"], - isTaxExempt: json["is_tax_exempt"], - hasShoppingCartItems: json["has_shopping_cart_items"], - active: json["active"], - deleted: json["deleted"], - isSystemAccount: json["is_system_account"], - systemName: json["system_name"], - lastIpAddress: json["last_ip_address"], - createdOnUtc: json["created_on_utc"], - lastLoginDateUtc: json["last_login_date_utc"], - lastActivityDateUtc: json["last_activity_date_utc"], - registeredInStoreId: json["registered_in_store_id"], - ); + fileNumber: json["file_number"], + iqamaNumber: json["iqama_number"], + isOutSa: json["is_out_sa"], + patientType: json["patient_type"], + gender: json["gender"], + birthDate: DateTime.parse(json["birth_date"]), + phone: json["phone"], + countryCode: json["country_code"], + yahalaAccountno: json["yahala_accountno"], + billingAddress: json["billing_address"], + shippingAddress: json["shipping_address"], + id: json["id"], + username: emailValues.map[json["username"]], + email: emailValues.map[json["email"]], + firstName: json["first_name"], + lastName: json["last_name"], + languageId: json["language_id"], + adminComment: json["admin_comment"], + isTaxExempt: json["is_tax_exempt"], + hasShoppingCartItems: json["has_shopping_cart_items"], + active: json["active"], + deleted: json["deleted"], + isSystemAccount: json["is_system_account"], + systemName: json["system_name"], + lastIpAddress: json["last_ip_address"], + createdOnUtc: json["created_on_utc"], + lastLoginDateUtc: json["last_login_date_utc"], + lastActivityDateUtc: json["last_activity_date_utc"], + registeredInStoreId: json["registered_in_store_id"], + ); Map toJson() => { - "file_number": fileNumber, - "iqama_number": iqamaNumber, - "is_out_sa": isOutSa, - "patient_type": patientType, - "gender": gender, - "birth_date": birthDate.toIso8601String(), - "phone": phone, - "country_code": countryCode, - "yahala_accountno": yahalaAccountno, - "billing_address": billingAddress, - "shipping_address": shippingAddress, - "id": id, - "username": emailValues.reverse[username], - "email": emailValues.reverse[email], - "first_name": firstName, - "last_name": lastName, - "language_id": languageId, - "admin_comment": adminComment, - "is_tax_exempt": isTaxExempt, - "has_shopping_cart_items": hasShoppingCartItems, - "active": active, - "deleted": deleted, - "is_system_account": isSystemAccount, - "system_name": systemName, - "last_ip_address": lastIpAddress, - "created_on_utc": createdOnUtc, - "last_login_date_utc": lastLoginDateUtc, - "last_activity_date_utc": lastActivityDateUtc, - "registered_in_store_id": registeredInStoreId, - }; + "file_number": fileNumber, + "iqama_number": iqamaNumber, + "is_out_sa": isOutSa, + "patient_type": patientType, + "gender": gender, + "birth_date": birthDate.toIso8601String(), + "phone": phone, + "country_code": countryCode, + "yahala_accountno": yahalaAccountno, + "billing_address": billingAddress, + "shipping_address": shippingAddress, + "id": id, + "username": emailValues.reverse[username], + "email": emailValues.reverse[email], + "first_name": firstName, + "last_name": lastName, + "language_id": languageId, + "admin_comment": adminComment, + "is_tax_exempt": isTaxExempt, + "has_shopping_cart_items": hasShoppingCartItems, + "active": active, + "deleted": deleted, + "is_system_account": isSystemAccount, + "system_name": systemName, + "last_ip_address": lastIpAddress, + "created_on_utc": createdOnUtc, + "last_login_date_utc": lastLoginDateUtc, + "last_activity_date_utc": lastActivityDateUtc, + "registered_in_store_id": registeredInStoreId, + }; } enum Email { STEVE_GATES_NOP_COMMERCE_COM } -final emailValues = EnumValues({ - "steve_gates@nopCommerce.com": Email.STEVE_GATES_NOP_COMMERCE_COM -}); +final emailValues = EnumValues({"steve_gates@nopCommerce.com": Email.STEVE_GATES_NOP_COMMERCE_COM}); class EnumValues { Map map; diff --git a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart index 14dab3e5..72399498 100644 --- a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart +++ b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart @@ -68,7 +68,7 @@ class _FooterWidgetState extends State { Padding( padding: const EdgeInsets.all(8.0), child: Text( - "Quantity", + TranslationBase.of(context).quantity, style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold), ), ), @@ -157,17 +157,19 @@ class _FooterWidgetState extends State { ), ], ), - onPressed: () { - setState(() { - if (showUI) { - quantityUI = 80; - showUI = false; - } else { - quantityUI = 160; - showUI = true; - } - }); - }, + onPressed: widget.isAvailable && !widget.item.isRx + ? () { + setState(() { + if (showUI) { + quantityUI = 80; + showUI = false; + } else { + quantityUI = 160; + showUI = true; + } + }); + } + : null, ), ), SizedBox( @@ -207,20 +209,20 @@ class _FooterWidgetState extends State { ); } else { await widget.addToShoppingCartFunction(quantity: widget.quantity, itemID: widget.item.id, model: widget.model); - Navigator.of(context).pushNamed( - CART_ORDER_PAGE, - ); - // Navigator.push( - // context, - // FadePage(page: CartOrderPage()), + // Navigator.of(context).pushNamed( + // CART_ORDER_PAGE, // ); + Navigator.push( + context, + FadePage(page: CartOrderPage()), + ); } }, fontWeight: FontWeight.w600, borderColor: Colors.grey[800], borderRadius: 3, disableColor: Colors.grey[700], - color: !widget.isAvailable && widget.quantity > 0 || widget.quantity > widget.quantityLimit || widget.item.rxMessage != null ? Colors.grey : Colors.grey[800], + color: !widget.isAvailable && widget.quantity > 0 || widget.quantity > widget.quantityLimit || widget.item.isRx ? Colors.grey : Colors.grey[800], ), ), ], diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index d33e3178..015df6ed 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -87,6 +87,9 @@ class __ProductDetailPageState extends State { Widget build(BuildContext context) { return BaseView( allowAny: true, + onModelReady: (model) { + model.getProductReviewsData(widget.product.id); + }, builder: (_, model, wi) => AppScaffold( appBarTitle: TranslationBase.of(context).productDetails, isShowAppBar: true, @@ -146,6 +149,7 @@ class __ProductDetailPageState extends State { notifyMeWhenAvailable(itemId: itemId, customerId: customerId, model: model); }, isInWishList: isInWishList, + isStockAvailable: model.isStockAvailable, ), ), SizedBox( @@ -302,10 +306,10 @@ class __ProductDetailPageState extends State { ), ), bottomSheet: FooterWidget( - widget.product.stockAvailability != 'Out of stock', + model.isStockAvailable, widget.product.orderMaximumQuantity, widget.product.orderMinimumQuantity, - widget.product.stockQuantity, + model.stockQuantity, widget.product, quantity: quantity, isOverQuantity: isOverQuantity, diff --git a/lib/pages/pharmacies/screens/product-details/product-name-and-price.dart b/lib/pages/pharmacies/screens/product-details/product-name-and-price.dart index 6d8ea11d..9401f3e0 100644 --- a/lib/pages/pharmacies/screens/product-details/product-name-and-price.dart +++ b/lib/pages/pharmacies/screens/product-details/product-name-and-price.dart @@ -1,7 +1,6 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; -import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:flutter/material.dart'; @@ -20,16 +19,12 @@ class ProductNameAndPrice extends StatefulWidget { final Function notifyMeWhenAvailable; final Function addToWishlistFunction; final Function deleteFromWishlistFunction; + final bool isStockAvailable; - AuthenticatedUserObject authenticatedUserObject = - locator(); + AuthenticatedUserObject authenticatedUserObject = locator(); ProductNameAndPrice(this.context, this.item, - {this.customerId, - this.isInWishList, - this.notifyMeWhenAvailable, - this.addToWishlistFunction, - this.deleteFromWishlistFunction}); + {this.customerId, this.isInWishList, this.notifyMeWhenAvailable, this.addToWishlistFunction, this.deleteFromWishlistFunction, @required this.isStockAvailable}); @override _ProductNameAndPriceState createState() => _ProductNameAndPriceState(); @@ -51,25 +46,18 @@ class _ProductNameAndPriceState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Texts(widget.item.price.toString() + " " + "SR", - fontWeight: FontWeight.bold, fontSize: 20), + Texts(widget.item.price.toString() + " " + TranslationBase.of(context).sar, fontWeight: FontWeight.bold, fontSize: 20), Texts( - projectViewModel.isArabic - ? widget.item.stockAvailabilityn - : widget.item.stockAvailability, + projectViewModel.isArabic ? widget.item.stockAvailabilityn : widget.item.stockAvailability, fontWeight: FontWeight.bold, fontSize: 15, - color: widget.item.stockAvailability == 'Out of stock' - ? Colors.red - : Colors.green, + color: widget.isStockAvailable ? Colors.green : Colors.red, ), // SizedBox(width: 20), if (widget.authenticatedUserObject.isLogin) - widget.item.stockAvailability == 'Out of stock' && - widget.customerId != null + widget.isStockAvailable && widget.customerId != null ? InkWell( - onTap: () => widget.notifyMeWhenAvailable( - context, widget.item.id), + onTap: () => widget.notifyMeWhenAvailable(context, widget.item.id), child: Row(children: [ Texts( TranslationBase.of(context).notifyMe, @@ -85,23 +73,15 @@ class _ProductNameAndPriceState extends State { ]), ) : IconWithBg( - icon: !widget.isInWishList - ? Icons.favorite_border - : Icons.favorite, - color: !widget.isInWishList - ? Colors.white - : Colors.red[800], + icon: !widget.isInWishList ? Icons.favorite_border : Icons.favorite, + color: !widget.isInWishList ? Colors.white : Colors.red[800], onPress: () async { { if (widget.customerId != null) { if (!widget.isInWishList) { - - await widget - .addToWishlistFunction(widget.item.id); - + await widget.addToWishlistFunction(widget.item.id); } else { - await widget - .deleteFromWishlistFunction(widget.item.id); + await widget.deleteFromWishlistFunction(widget.item.id); } } else { return; @@ -118,13 +98,9 @@ class _ProductNameAndPriceState extends State { child: Container( margin: EdgeInsets.only(left: 5), child: Align( - alignment: projectViewModel.isArabic - ? Alignment.topRight - : Alignment.topLeft, + alignment: projectViewModel.isArabic ? Alignment.topRight : Alignment.topLeft, child: Text( - projectViewModel.isArabic - ? widget.item.namen - : widget.item.name, + projectViewModel.isArabic ? widget.item.namen : widget.item.name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15), ), ), @@ -140,8 +116,7 @@ class _ProductNameAndPriceState extends State { child: Row( children: [ RatingBar.readOnly( - initialRating: double.parse( - widget.item.approvedRatingSum.toString()), + initialRating: double.parse(widget.item.approvedRatingSum.toString()), size: 15.0, filledColor: Colors.yellow[700], emptyColor: Colors.grey[400], @@ -172,19 +147,9 @@ class _ProductNameAndPriceState extends State { Row( children: [ Text( - projectViewModel.isArabic - ? widget.item.rxMessagen.toString() - : widget.item.rxMessage.toString(), + projectViewModel.isArabic ? widget.item.rxMessagen.toString() : widget.item.rxMessage.toString(), style: TextStyle(color: Colors.red, fontSize: 10), ), - SizedBox( - width: 5, - ), - Icon( - FontAwesomeIcons.questionCircle, - color: Colors.red, - size: 15.0, - ) ], ) ], diff --git a/lib/services/pharmacy_services/product_detail_service.dart b/lib/services/pharmacy_services/product_detail_service.dart index 47673eab..23379914 100644 --- a/lib/services/pharmacy_services/product_detail_service.dart +++ b/lib/services/pharmacy_services/product_detail_service.dart @@ -15,36 +15,53 @@ import 'package:diplomaticquarterapp/uitl/app_toast.dart'; class ProductDetailService extends BaseService { bool isLogin = false; + num _stockQuantity; + + num get stockQuantity => _stockQuantity; + + String _stockAvailability; + + String get stockAvailability => _stockAvailability; + + bool _isStockAvailable; + + bool get isStockAvailable => _isStockAvailable; + List _productDetailList = List(); + List get productDetailList => _productDetailList; List _productLocationList = List(); + List get productLocationList => _productLocationList; List _addToCartModel = List(); + List get addToCartModel => _addToCartModel; List _wishListProducts = List(); + List get wishListProducts => _wishListProducts; List _productSpecification = List(); - List get productSpecification => _productSpecification; - + List get productSpecification => _productSpecification; Future getProductReviews(productID) async { hasError = false; - await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL+productID+"?fields=reviews", - onSuccess: (dynamic response, int statusCode) { - _productDetailList.clear(); - response['products'].forEach((item) { - _productDetailList.add(ProductDetail.fromJson(item)); - print(response); - }); - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - }); + await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL + productID + "?fields=reviews,stock_quantity,stock_availability,IsStockAvailable", onSuccess: (dynamic response, int statusCode) { + _productDetailList.clear(); + response['products'].forEach((item) { + _productDetailList.add(ProductDetail.fromJson(item)); + print(response); + }); + _stockQuantity = response['products'][0]['stock_quantity']; + _stockAvailability = response['products'][0]['stock_availability']; + _isStockAvailable = response['products'][0]['IsStockAvailable']; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }); } Future getProductAvailabiltyDetail() async { @@ -52,29 +69,28 @@ class ProductDetailService extends BaseService { Map request; request = { - "Channel": 3, - "DeviceTypeID": 2, - "IPAdress": "10.20.10.20", - "LanguageID": 2, - "PatientOutSA": 0, - "SKU": "6720020025", - "SessionID": null, - "VersionID": 5.6, - "generalid": "Cs2020@2016\$2958", - "isDentalAllowedBackend": false + // "Channel": 3, + // "DeviceTypeID": 2, + // "IPAdress": "10.20.10.20", + // "LanguageID": 2, + // "PatientOutSA": 0, + // "SKU": "6720020025", + // "SessionID": null, + // "VersionID": 5.6, + // "generalid": "Cs2020@2016\$2958", + // "isDentalAllowedBackend": false }; - await baseAppClient.post(GET_LOCATION, - onSuccess: (dynamic response, int statusCode) { - _productLocationList.clear(); - response['PharmList'].forEach((item) { - _productLocationList.add(LocationModel.fromJson(item)); - print(_productLocationList); - print(response); - }); - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - }, body: request); + await baseAppClient.post(GET_LOCATION, onSuccess: (dynamic response, int statusCode) { + _productLocationList.clear(); + response['PharmList'].forEach((item) { + _productLocationList.add(LocationModel.fromJson(item)); + print(_productLocationList); + print(response); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: request); } Future addToCart(quantity, itemID) async { @@ -83,30 +99,22 @@ class ProductDetailService extends BaseService { Map request; request = { - "shopping_cart_item": - { - "quantity": quantity, - "shopping_cart_type": "1", - "product_id": itemID, - "customer_id": customerId, - "language_id": 1 - } + "shopping_cart_item": {"quantity": quantity, "shopping_cart_type": "1", "product_id": itemID, "customer_id": customerId, "language_id": 1} }; dynamic localRes; - - await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false, - onSuccess: (dynamic response, int statusCode) { - _addToCartModel.clear(); - response['shopping_carts'].forEach((item) { - _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); + + await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false, onSuccess: (dynamic response, int statusCode) { + _addToCartModel.clear(); + response['shopping_carts'].forEach((item) { + _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); } @@ -118,7 +126,7 @@ class ProductDetailService extends BaseService { }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; - AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); + AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage()); }); } @@ -130,67 +138,61 @@ class ProductDetailService extends BaseService { request = { "shopping_cart_item": {"quantity": 1, "shopping_cart_type": "Wishlist", "product_id": itemID, "customer_id": customerId, "language_id": 1} }; - await baseAppClient.pharmacyPost(GET_SHOPPING_CART, - onSuccess: (dynamic response, int statusCode) { - _wishListProducts.clear(); - response['shopping_carts'].forEach((item) { - _wishListProducts.add(Wishlist.fromJson(item)); - }); - AppToast.showSuccessToast(message: 'You have added a product to the Wishlist'); - - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); - }, body: request); + await baseAppClient.pharmacyPost(GET_SHOPPING_CART, onSuccess: (dynamic response, int statusCode) { + _wishListProducts.clear(); + response['shopping_carts'].forEach((item) { + _wishListProducts.add(Wishlist.fromJson(item)); + }); + AppToast.showSuccessToast(message: 'You have added a product to the Wishlist'); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage()); + }, body: request); } Future getWishlistItems() async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; - await baseAppClient.getPharmacy(GET_WISHLIST+customerId+"?shopping_cart_type=2", - onSuccess: (dynamic response, int statusCode) { - _wishListProducts.clear(); - response['shopping_carts'].forEach((item) { - _wishListProducts.add(Wishlist.fromJson(item)); - }); - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - }); + await baseAppClient.getPharmacy(GET_WISHLIST + customerId + "?shopping_cart_type=2", onSuccess: (dynamic response, int statusCode) { + _wishListProducts.clear(); + response['shopping_carts'].forEach((item) { + _wishListProducts.add(Wishlist.fromJson(item)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }); } Future deleteItemFromWishlist(itemID) async { var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); hasError = false; - await baseAppClient.getPharmacy(DELETE_WISHLIST+customerId+"+&product_id="+itemID+"&cart_type=Wishlist", - onSuccess: (dynamic response, int statusCode) { - _wishListProducts.clear(); - response['shopping_carts'].forEach((item) { - _wishListProducts.add(Wishlist.fromJson(item)); - }); - AppToast.showSuccessToast(message: 'You have removed a product from the Wishlist'); - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); - }); + await baseAppClient.getPharmacy(DELETE_WISHLIST + customerId + "+&product_id=" + itemID + "&cart_type=Wishlist", onSuccess: (dynamic response, int statusCode) { + _wishListProducts.clear(); + response['shopping_carts'].forEach((item) { + _wishListProducts.add(Wishlist.fromJson(item)); + }); + AppToast.showSuccessToast(message: 'You have removed a product from the Wishlist'); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage()); + }); } Future productSpecificationData(itemID) async { hasError = false; - await baseAppClient.getPharmacy(GET_SPECIFICATION+itemID, - onSuccess: (dynamic response, int statusCode) { - _productSpecification.clear(); - response['specification'].forEach((item) { - _productSpecification.add(SpecificationModel.fromJson(item)); - print(_productSpecification); - }); - }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; - }); + await baseAppClient.getPharmacy(GET_SPECIFICATION + itemID, onSuccess: (dynamic response, int statusCode) { + _productSpecification.clear(); + response['specification'].forEach((item) { + _productSpecification.add(SpecificationModel.fromJson(item)); + print(_productSpecification); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }); } - }