diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 3979e982..ee86ca74 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -1091,6 +1091,8 @@ const Map localizedValues = { "camera-permission": {"en": "Camera", "ar": "الكاميرا"}, "location-permission": {"en": "Location", "ar": "تحديد المواقع"}, + "needPrescription": {"en": "This product requires a prescription", "ar": " هذا المنتج يتطلب وصفة طبية"}, + "outOfStockMsg": {"en": "You have added product which is out of stock now, Please remove that!", "ar": "لقد قمت بإضافة المنتج الذي نفذ من المخزون الآن. يرجى إزالة ذلك"}, "accessibility": {"en": "Accessibility Mode", "ar": "وضع امكانية الوصول"}, "orderStatus": {"en": "Order Status", "ar": "حالة الطلب"}, "CancelOrder": {"en": "Cancel Order", "ar": "الغاء الطلب"}, diff --git a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart index 7c86f6b7..0a03b2ca 100644 --- a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart @@ -42,9 +42,11 @@ class OrderPreviewViewModel extends BaseViewModel { getShoppingCart(); } } - void update(){ + + void update() { notifyListeners(); } + Future getShoppingCart() async { // setState(ViewState.Busy); // GifLoaderDialogUtils.showMyDialog( @@ -61,7 +63,7 @@ class OrderPreviewViewModel extends BaseViewModel { } // GifLoaderDialogUtils.hideDialog( // locator().navigatorKey.currentContext); - setState(ViewState.Idle); + setState(ViewState.Idle); } } @@ -215,6 +217,17 @@ class OrderPreviewViewModel extends BaseViewModel { setState(ViewState.Idle); } } + + bool isCartItemsOutOfStock() { + bool outOfStock = false; + for (int i = 0; i < cartResponse.shoppingCarts.length; i++) { + if (cartResponse.shoppingCarts[i].product.stockQuantity == 0) { + outOfStock = true; + break; + } + } + return outOfStock; + } } enum PaymentOption { meda, sadad, visa, mastercard, installments } diff --git a/lib/pages/final_products_page.dart b/lib/pages/final_products_page.dart index fff272b3..7e8385f0 100644 --- a/lib/pages/final_products_page.dart +++ b/lib/pages/final_products_page.dart @@ -1,5 +1,11 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacy_categorise_view_model.dart'; +import 'package:diplomaticquarterapp/locator.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-order-page.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; @@ -16,6 +22,8 @@ dynamic languageID; class FinalProductsPage extends StatefulWidget { final String id; final int productType; // 1 : default, 2 : manufacturer , 3 : recently viewed + AuthenticatedUserObject authenticatedUserObject = + locator(); FinalProductsPage({this.id, this.productType = 1}); @@ -488,7 +496,7 @@ class _FinalProductsPageState extends State { context) .size .width / - 3.5 + 5.3 : 0, padding: EdgeInsets.all( @@ -605,6 +613,31 @@ class _FinalProductsPageState extends State { ], ), ), + + widget.authenticatedUserObject.isLogin + ? Container( + child: IconButton( + icon: Icon(Icons.shopping_cart, + size: 18, + color: Colors.blue,), + onPressed: () async { + GifLoaderDialogUtils.showMyDialog(context); + if(model.finalProducts[index].rxMessage == null){ + await addToCartFunction(1, model.finalProducts[index].id); +// GifLoaderDialogUtils.hideDialog(context); + Navigator.push( + context, + FadePage(page: CartOrderPage()), + ); + } + else{ + AppToast.showErrorToast(message: TranslationBase.of(context).needPrescription); + } + GifLoaderDialogUtils.hideDialog(context); + } + + ), + ):Container(), ], ), ), @@ -651,4 +684,9 @@ class _FinalProductsPageState extends State { ), )); } + + addToCartFunction(quantity, itemID) async { + ProductDetailViewModel x = new ProductDetailViewModel(); + await x.addToCartData(quantity, itemID); + } } diff --git a/lib/pages/landing/landing_page_pharmcy.dart b/lib/pages/landing/landing_page_pharmcy.dart index 8b2204f4..6ae272e2 100644 --- a/lib/pages/landing/landing_page_pharmcy.dart +++ b/lib/pages/landing/landing_page_pharmcy.dart @@ -50,7 +50,7 @@ class _LandingPagePharmacyState extends State { @override Widget build(BuildContext context) { return WillPopScope( - onWillPop: ()async{ + onWillPop: () async { return false; }, child: Scaffold( diff --git a/lib/pages/parent_categorise_page.dart b/lib/pages/parent_categorise_page.dart index ff1fc5b7..1ac20946 100644 --- a/lib/pages/parent_categorise_page.dart +++ b/lib/pages/parent_categorise_page.dart @@ -1,9 +1,15 @@ import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/model/pharmacy/categorise_parent_model.dart'; +import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacy_categorise_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; +import 'package:diplomaticquarterapp/locator.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-order-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; import 'package:diplomaticquarterapp/pages/sub_categorise_page.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; @@ -15,14 +21,19 @@ import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import 'package:diplomaticquarterapp/pages/sub_categories_modalsheet.dart'; import 'base/base_view.dart'; + class ParentCategorisePage extends StatefulWidget { String id; String titleName; + AuthenticatedUserObject authenticatedUserObject = + locator(); + ParentCategorisePage({this.id, this.titleName}); @override @@ -33,8 +44,11 @@ class ParentCategorisePage extends StatefulWidget { class _ParentCategorisePageState extends State { String id; String titleName; + final dynamic productID; + + - _ParentCategorisePageState({this.id, this.titleName}); + _ParentCategorisePageState({this.id, this.titleName, this.productID,}); Map values = {'huusam': false, 'ali': false, 'noor': false}; bool checkedBrands = false; @@ -1034,7 +1048,7 @@ class _ParentCategorisePageState extends State { context) .size .width / - 5 + 5.3 : 0, padding: EdgeInsets.all(4), @@ -1117,8 +1131,7 @@ class _ParentCategorisePageState extends State { padding: const EdgeInsets .only( - top: 4, - bottom: 4), + top: 4, bottom: 4), child: Texts( "SAR ${model.parentProducts[index].price}", bold: true, @@ -1154,6 +1167,30 @@ class _ParentCategorisePageState extends State { ], ), ), + + widget.authenticatedUserObject.isLogin ? + Container( + child: IconButton( + icon: Icon(Icons.shopping_cart, + size: 18, + color: Colors.blue,), + onPressed: () async { + GifLoaderDialogUtils.showMyDialog(context); + if(model.parentProducts[index].rxMessage == null){ + await addToCartFunction(1, model.parentProducts[index].id); + Navigator.push( + context, + FadePage(page: CartOrderPage()), + ); + } + else{ + AppToast.showErrorToast(message: TranslationBase.of(context).needPrescription); + } + GifLoaderDialogUtils.hideDialog(context); + } + + ), + ): Container(), ], ), ), @@ -1201,6 +1238,13 @@ class _ParentCategorisePageState extends State { ), ), )); + + + } + + addToCartFunction(quantity, itemID) async { + ProductDetailViewModel x = new ProductDetailViewModel(); + await x.addToCartData(quantity, itemID); } bool isEntityListSelected(CategoriseParentModel masterKey) { @@ -1220,4 +1264,7 @@ class _ParentCategorisePageState extends State { } return false; } + + + } diff --git a/lib/pages/pharmacies/product-brands.dart b/lib/pages/pharmacies/product-brands.dart index 42a78d5c..fb3e38e4 100644 --- a/lib/pages/pharmacies/product-brands.dart +++ b/lib/pages/pharmacies/product-brands.dart @@ -97,7 +97,7 @@ class _ProductBrandsPageState extends State { height: 10, ), Container( - height: 290, + height: 420, width: double.infinity, color: Colors.white, child: ListView.builder( diff --git a/lib/pages/pharmacies/screens/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-order-page.dart new file mode 100644 index 00000000..f9c928eb --- /dev/null +++ b/lib/pages/pharmacies/screens/cart-order-page.dart @@ -0,0 +1,454 @@ +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; +import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; +import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/screens/pharmacy-terms-conditions-page.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductOrderItem.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/GestureIconButton.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; +import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; +import 'package:flutter/material.dart'; +import 'package:http/http.dart'; +import 'package:provider/provider.dart'; + +import 'cart-page/cart-order-preview.dart'; + +class CartOrderPage extends StatefulWidget { + + + const CartOrderPage({ Key key}) + : super(key: key); + + + @override + _CartOrderPageState createState() => _CartOrderPageState(); +} + +class _CartOrderPageState extends State { + bool isLoading = true; + + @override + void initState() { + super.initState(); + getData(); + + } + + @override + Widget build(BuildContext context) { + final mediaQuery = MediaQuery.of(context); + OrderPreviewViewModel model = Provider.of(context); + + final height = mediaQuery.size.height - 60 - mediaQuery.padding.top; + AppScaffold appScaffold; + return NetworkBaseView( + // baseViewModel: model, + isLoading: isLoading, + isLocalLoader: true, + child: AppScaffold( + appBarTitle: TranslationBase.of(context).shoppingCart, + isShowAppBar: true, + isPharmacy: true, + showHomeAppBarIcon: false, + isShowDecPage: true, + baseViewModel: model, + backgroundColor: Colors.white, + body: !(model.cartResponse.shoppingCarts == null || + model.cartResponse.shoppingCarts.length == 0) + ? Container( + height: height * 0.85, + width: double.infinity, + child: SingleChildScrollView( + child: Container( + margin: EdgeInsets.all(10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + GestureIconButton( + TranslationBase.of(context).deleteAllItems, + Icon( + Icons.delete_outline_sharp, + color: Colors.grey.shade700, + ), + onTap: () => {model.deleteShoppingCart()}, + ), + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 1, + indent: 0, + endIndent: 0, + ), + Container( + child: Column( + children: [ + ...List.generate( + model.cartResponse.shoppingCarts != null + ? model.cartResponse.shoppingCarts.length + : 0, + (index) => ProductOrderItem( + model.cartResponse + .shoppingCarts[index], () { + print(model.cartResponse + .shoppingCarts[index].quantity); + model + .changeProductQuantity(model + .cartResponse + .shoppingCarts[index]) + .then((value) { + if (model.state != ViewState.Error) { + appScaffold.appBar.badgeUpdater( + '${value.quantityCount ?? 0}'); + } + if (model.state == + ViewState.ErrorLocal) { + Utils.showErrorToast(model.error); + } + }); + }, () { + model + .deleteProduct(model.cartResponse + .shoppingCarts[index]) + .then((value) { + if (model.state != ViewState.Error) { + appScaffold.appBar.badgeUpdater( + '${value.quantityCount ?? 0}'); + } + }); + })) + ], + ), + ), + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 2, + indent: 0, + endIndent: 0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + TranslationBase.of(context).subtotal, + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + Texts( + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotal).toStringAsFixed(2)}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ], + ), + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 1, + indent: 0, + endIndent: 0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + "${TranslationBase.of(context).vat}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + Texts( + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotalVatAmount).toStringAsFixed(2)}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ], + ), + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 1, + indent: 0, + endIndent: 0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts( + TranslationBase.of(context).total, + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.bold, + ), + Texts( + "${TranslationBase.of(context).sar} ${(model.cartResponse.subtotalWithVat).toStringAsFixed(2)}", + fontSize: 14, + color: Colors.black, + fontWeight: FontWeight.bold, + ), + ], + ), + const Divider( + color: Color(0xFFD6D6D6), + height: 20, + thickness: 1, + indent: 0, + endIndent: 0, + ), + Image.asset( + "assets/images/pharmacy_module/payment_image.png", + width: mediaQuery.size.width - 20, + height: 30.0, + fit: BoxFit.scaleDown, + ), + SizedBox( + height: 120, + ) + ], + ), + ), + ), + ) + : Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: Image.asset( + 'assets/images/new-design/empty_box.png', + width: 100, + height: 100, + fit: BoxFit.cover, + ), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + TranslationBase.of(context).noData, +// 'There is no data', + style: TextStyle(fontSize: 30), + ), + ) + ], + ), + ), + bottomSheet: Container( + height: !(model.cartResponse.shoppingCarts == null || + model.cartResponse.shoppingCarts.length == 0) + ? height * 0.15 + : 0, + color: Colors.white, + child: OrderBottomWidget(model.addresses, height), + ), + ), + ); + } + + void getData() async { + await Provider.of(context, listen: false) + .getShoppingCart(); + setState(() { + isLoading = false; + }); + } +} + +class OrderBottomWidget extends StatefulWidget { + final List addresses; + final double height; + + OrderBottomWidget(this.addresses, this.height); + + @override + _OrderBottomWidgetState createState() => _OrderBottomWidgetState(); +} + +class _OrderBottomWidgetState extends State { + bool isAgree = false; + + @override + Widget build(BuildContext context) { + ProjectViewModel projectProvider = Provider.of(context); + OrderPreviewViewModel cart = Provider.of(context); + return !(cart.cartResponse.shoppingCarts == null || + cart.cartResponse.shoppingCarts.length == 0) + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Divider( + color: Color(0xFFD6D6D6), + height: 1, + thickness: 1, + indent: 0, + endIndent: 0, + ), + Container( + height: widget.height * 0.070, + color: Color(0xffe6ffe0), + padding: EdgeInsets.symmetric(horizontal: 4), + child: Row( + children: [ + InkWell( + onTap: () { + setState(() { + isAgree = !isAgree; + }); + }, + child: Container( + width: 25.0, + height: widget.height * 0.070, + decoration: new BoxDecoration( + color: !isAgree ? Color(0xffeeeeee) : Colors.green, + shape: BoxShape.circle, + ), + child: !isAgree + ? null + : Padding( + padding: const EdgeInsets.all(0.0), + child: Icon( + Icons.check, + color: Colors.white, + size: 25, + ), + ), + ), + ), + Expanded( + child: Container( + padding: EdgeInsets.symmetric(horizontal: 4), + margin: const EdgeInsets.symmetric(vertical: 4), + child: Texts( + TranslationBase.of(context) + .pharmacyServiceTermsCondition, + fontSize: 13, + color: Colors.grey.shade800, + fontWeight: FontWeight.normal, + ), + ), + ), + InkWell( + onTap: () => { + Navigator.push( + context, FadePage(page: PharmacyTermsConditions())) + }, + child: Container( + child: Icon( + Icons.info, + size: 25, + color: Color(0xff005aff), + ), + ), + ), + ], + ), + ), + Container( + height: widget.height * 0.065, + margin: EdgeInsets.symmetric(vertical: 2), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + margin: EdgeInsets.symmetric( + horizontal: 0, vertical: 0), + child: Row( + children: [ + Texts( + "${TranslationBase.of(context).sar} ${(cart.cartResponse.subtotalWithVat).toStringAsFixed(2)}", + fontSize: projectProvider.isArabic ? 12 : 14, + fontWeight: FontWeight.bold, + ), + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 4), + child: Texts( + "${TranslationBase.of(context).inclusiveVat}", + fontSize: 8, + color: Colors.grey, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + Texts( + "${cart.cartResponse.quantityCount} ${TranslationBase.of(context).items}", + fontSize: 10, + color: Colors.grey, + fontWeight: FontWeight.bold, + ), + ], + ), + ), + RaisedButton( + onPressed: isAgree +// && cart.cartResponse.shoppingCarts[1].product.stockQuantity ==0 + ? () => { + if(cart.isCartItemsOutOfStock()){ + // Toast msg + AppToast.showErrorToast(message: TranslationBase.of(context).outOfStockMsg) + }else { + Navigator.push( + context, + FadePage( + page: + OrderPreviewPage(widget.addresses))) + } + } + : null, + child: new Text( + "${TranslationBase.of(context).checkOut}", + style: new TextStyle( + color: + isAgree ? Colors.white : Colors.grey.shade300, + fontSize: 14), + ), + color: Color(0xff005aff), + disabledColor: Color(0xff005aff), + ) +// RaisedButton( +// onPressed: isAgree +//// && cart.cartResponse.shoppingCarts[1].product.stockQuantity ==0 +// ? () => { +// Navigator.push( +// context, +// FadePage( +// page: +// OrderPreviewPage(widget.addresses))) +// } +// : null, +// child: new Text( +// "${TranslationBase.of(context).checkOut}", +// style: new TextStyle( +// color: +// isAgree ? Colors.white : Colors.grey.shade300, +// fontSize: 14), +// ), +// color: Color(0xff005aff), +// disabledColor: Color(0xff005aff), +// ) + ], + ), + ), + ], + ) + : Container(); + } +} diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index ef3b7d8a..83a76a19 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -313,7 +313,12 @@ class __ProductDetailPageState extends State { SizedBox( height: 10, ), - RecommendedProducts(product: widget.product) + RecommendedProducts(product: widget.product,productDetailViewModel: model, + addToWishlistFunction: (itemID) async { + await addToWishlistFunction(itemID: itemID, model: model); + }, deleteFromWishlistFunction: (itemID) async { + await deleteFromWishlistFunction(itemID: itemID, model: model); + },) ], ), ), diff --git a/lib/pages/pharmacies/screens/product-details/recommended_products.dart b/lib/pages/pharmacies/screens/product-details/recommended_products.dart index 2070a29e..6e0fbba9 100644 --- a/lib/pages/pharmacies/screens/product-details/recommended_products.dart +++ b/lib/pages/pharmacies/screens/product-details/recommended_products.dart @@ -1,9 +1,11 @@ import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.dart'; +import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; +import 'package:diplomaticquarterapp/locator.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; @@ -24,6 +26,9 @@ class RecommendedProducts extends StatefulWidget { final Function addToWishlistFunction; final Function deleteFromWishlistFunction; + AuthenticatedUserObject authenticatedUserObject = + locator(); + RecommendedProducts( {Key key, this.product, @@ -134,63 +139,27 @@ class _RecommendedProductsState extends State { child: Align( alignment: Alignment.topRight, child: IconButton( - icon: Icon(model - .recommendedProductList[ - index] - .isinwishlist != - true - ? Icons.favorite_border - : Icons.favorite), - color: model - .recommendedProductList[ - index] - .isinwishlist != - true - ? Colors.grey - : Colors.red, + icon: Icon(model.recommendedProductList[index].isinwishlist != true + ? Icons.favorite_border : Icons.favorite), + color: model.recommendedProductList[index].isinwishlist != true + ? Colors.grey : Colors.red, onPressed: () async { - if (widget.customerId != null) { - if (!widget.isInWishList && - model - .recommendedProductList[ - index] - .isinwishlist != - true) { - GifLoaderDialogUtils - .showMyDialog(context); - await widget.addToWishlistFunction( - itemID: model - .recommendedProductList[ - index] - .id, - model: widget - .productDetailViewModel); -// checkWishlist(); - GifLoaderDialogUtils - .hideDialog(context); + if (widget.authenticatedUserObject.isLogin + ) { + if (!widget.isInWishList && model.recommendedProductList[index].isinwishlist != true) { + GifLoaderDialogUtils.showMyDialog(context); + await widget.addToWishlistFunction(model.recommendedProductList[index].id, + ); + GifLoaderDialogUtils.hideDialog(context); setState(() { - model - .recommendedProductList[ - index] - .isinwishlist = true; - }); + model.recommendedProductList[index].isinwishlist = true;}); } else { - GifLoaderDialogUtils - .showMyDialog(context); - await widget.deleteFromWishlistFunction( - itemID: model - .recommendedProductList[ - index] - .id, - model: widget - .productDetailViewModel); - GifLoaderDialogUtils - .hideDialog(context); + GifLoaderDialogUtils.showMyDialog(context); + await widget.deleteFromWishlistFunction(model.recommendedProductList[index].id, + ); + GifLoaderDialogUtils.hideDialog(context); setState(() { - model - .recommendedProductList[ - index] - .isinwishlist = false; + model.recommendedProductList[index].isinwishlist = false; }); } } else { diff --git a/lib/pages/pharmacies/widgets/ProductOrderItem.dart b/lib/pages/pharmacies/widgets/ProductOrderItem.dart index d7a82cc6..cb7c59fd 100644 --- a/lib/pages/pharmacies/widgets/ProductOrderItem.dart +++ b/lib/pages/pharmacies/widgets/ProductOrderItem.dart @@ -45,6 +45,7 @@ class _ProductOrderItemState extends State { ), title: Container( child: Row( +// widget.item.product.stock_quantity===0 crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ @@ -166,10 +167,22 @@ class _ProductOrderItemState extends State { "$_totalPrice ${projectProvider.isArabic ? widget.item.currencyn : widget.item.currency}", fontSize: 12, fontWeight: FontWeight.bold, - ) + ), + widget.item.product.stockQuantity == 0 ? + Texts( + projectProvider.isArabic + ? widget.item.product.stockAvailabilityn + : widget.item.product.stockAvailability, + fontWeight: FontWeight.normal, + fontSize: 13, + color:Colors.red, + + ): Texts(""), ], ), - ) + ), + + ], ), ) diff --git a/lib/pages/sub_categories_modalsheet.dart b/lib/pages/sub_categories_modalsheet.dart index f1ff0e08..d6499c8e 100644 --- a/lib/pages/sub_categories_modalsheet.dart +++ b/lib/pages/sub_categories_modalsheet.dart @@ -42,6 +42,7 @@ class _SubCategoriseModalsheetState extends State { appBarTitle: TranslationBase.of(context).categorise, isBottomBar: false, isShowAppBar: true, + isPharmacy: true, backgroundColor: Colors.white, isShowDecPage: false, baseViewModel: model, diff --git a/lib/pages/sub_categorise_page.dart b/lib/pages/sub_categorise_page.dart index bfa7e343..3fb1574f 100644 --- a/lib/pages/sub_categorise_page.dart +++ b/lib/pages/sub_categorise_page.dart @@ -1,6 +1,11 @@ import 'package:diplomaticquarterapp/core/model/pharmacy/categorise_parent_model.dart'; +import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacy_categorise_view_model.dart'; +import 'package:diplomaticquarterapp/locator.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-order-page.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; @@ -20,6 +25,9 @@ class SubCategorisePage extends StatefulWidget { String title; String parentId; + AuthenticatedUserObject authenticatedUserObject = + locator(); + SubCategorisePage({this.id, this.parentId, this.title}); @override @@ -942,7 +950,7 @@ class _SubCategorisePageState extends State { context) .size .width / - 5 + 5.3 : 0, padding: EdgeInsets.all(4), @@ -1057,6 +1065,29 @@ class _SubCategorisePageState extends State { ], ), ), + widget.authenticatedUserObject.isLogin? + Container( + child: IconButton( + icon: Icon(Icons.shopping_cart, + size: 18, + color: Colors.blue,), + onPressed: () async { + GifLoaderDialogUtils.showMyDialog(context); + if(model.subProducts[index].rxMessage == null){ + await addToCartFunction(1, model.subProducts[index].id); +// GifLoaderDialogUtils.hideDialog(context); + Navigator.push( + context, + FadePage(page: CartOrderPage()), + );} + else{ + AppToast.showErrorToast(message: TranslationBase.of(context).needPrescription); + } + GifLoaderDialogUtils.hideDialog(context); + } + + ), + ):Container(), ], ), ), @@ -1123,4 +1154,8 @@ class _SubCategorisePageState extends State { } return false; } + addToCartFunction(quantity, itemID) async { + ProductDetailViewModel x = new ProductDetailViewModel(); + await x.addToCartData(quantity, itemID); + } } diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index d8c3ff7b..6a131d09 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -1365,6 +1365,8 @@ class TranslationBase { String get referralNumber => localizedValues['referralNumber'][locale.languageCode]; + String get needPrescription => localizedValues['needPrescription'][locale.languageCode]; + String get outOfStockMsg => localizedValues['outOfStockMsg'][locale.languageCode]; String get requestID => localizedValues['requestID'][locale.languageCode]; String get OrderStatus => localizedValues['OrderStatus'][locale.languageCode]; String get pickupDate => localizedValues['pickupDate'][locale.languageCode];