From 7de8c2588fb333e7830332f02f2f7704f71ca7dc Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 16:17:34 +0300 Subject: [PATCH 1/4] fix coloring issue --- .../product-details/footor/footer-widget.dart | 11 +- .../product-name-and-price.dart | 127 +++++++++--------- .../product-details/shared/icon_with_bg.dart | 14 +- .../shared/product_details_app_bar.dart | 4 +- 4 files changed, 82 insertions(+), 74 deletions(-) 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 43abcae5..854f5d4c 100644 --- a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart +++ b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart @@ -31,7 +31,7 @@ class FooterWidget extends StatefulWidget { } class _FooterWidgetState extends State { - double quantityUI = 70; + double quantityUI = 80; bool showUI = false; AuthenticatedUserObject authenticatedUserObject = locator(); @@ -77,7 +77,7 @@ class _FooterWidgetState extends State { child: Icon(Icons.close, color: Colors.black), onTap: () { setState(() { - quantityUI = 70; + quantityUI = 80; showUI = false; }); }, @@ -172,7 +172,7 @@ class _FooterWidgetState extends State { onPressed: () { setState(() { if (showUI) { - quantityUI = 70; + quantityUI = 80; showUI = false; } else { quantityUI = 150; @@ -189,7 +189,7 @@ class _FooterWidgetState extends State { disabled: !widget.isAvailable && widget.quantity > 0 || widget.quantity > widget.quantityLimit || widget.item.rxMessage != null, - disableColor: Colors.green[400], + disableColor: Color(0xFF4CAF50), onTap: () async { if (!authenticatedUserObject.isLogin) { Navigator.of(context).pushNamed( @@ -199,8 +199,9 @@ class _FooterWidgetState extends State { await widget.addToCartFunction( widget.quantity, widget.item.id, context); }, + borderColor: Color(0xFF4CAF50), borderRadius: 5, - color: Colors.green, + color: Color(0xFF4CAF50), ), ), SizedBox( 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 4301ce36..31662219 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 @@ -22,7 +22,7 @@ class ProductNameAndPrice extends StatefulWidget { final Function deleteFromWishlistFunction; AuthenticatedUserObject authenticatedUserObject = - locator(); + locator(); ProductNameAndPrice(this.context, this.item, {this.customerId, @@ -64,50 +64,52 @@ class _ProductNameAndPriceState extends State { : Colors.green, ), // SizedBox(width: 20), - if(widget.authenticatedUserObject.isLogin) - widget.item.stockAvailability == 'Out of stock' && - widget.customerId != null - ? InkWell( - onTap: () => - widget.notifyMeWhenAvailable(context, widget.item.id), - child: Row(children: [ - Texts( - TranslationBase.of(context).notifyMe, - decoration: TextDecoration.underline, - color: Colors.blue, - ), - SizedBox(width: 4), - Icon( - FontAwesomeIcons.bell, - color: Colors.blue, - size: 15.0, - ) - ]), - ) - : IconWithBg( - icon: !widget.isInWishList - ? Icons.favorite_border - : Icons.favorite, - color: !widget.isInWishList ? Colors.white : Colors.red, - onPress: () async { - { - if (widget.customerId != null) { - if (!widget.isInWishList) { - GifLoaderDialogUtils.showMyDialog(context); - await widget - .addToWishlistFunction(widget.item.id); - GifLoaderDialogUtils.hideDialog(context); + if (widget.authenticatedUserObject.isLogin) + widget.item.stockAvailability == 'Out of stock' && + widget.customerId != null + ? InkWell( + onTap: () => widget.notifyMeWhenAvailable( + context, widget.item.id), + child: Row(children: [ + Texts( + TranslationBase.of(context).notifyMe, + decoration: TextDecoration.underline, + color: Colors.blue, + ), + SizedBox(width: 4), + Icon( + FontAwesomeIcons.bell, + color: Colors.blue, + size: 15.0, + ) + ]), + ) + : IconWithBg( + 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) { + GifLoaderDialogUtils.showMyDialog(context); + await widget + .addToWishlistFunction(widget.item.id); + GifLoaderDialogUtils.hideDialog(context); + } else { + await widget + .deleteFromWishlistFunction(widget.item.id); + } } else { - await widget - .deleteFromWishlistFunction(widget.item.id); + return; } - } else { - return; + setState(() {}); } - setState(() {}); - } - }, - ) + }, + ) ], ), ), @@ -163,29 +165,32 @@ class _ProductNameAndPriceState extends State { "(${widget.item.approvedTotalReviews}${TranslationBase.of(context).review})", fontSize: 12, ), + SizedBox( + width: 70, + ), + if (widget.item.rxMessage != null) + Row( + children: [ + Text( + 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, + ) + ], + ) ], ), ), ), - Expanded( - flex: 1, - child: Container( - child: widget.item.rxMessage != null - ? Text( - projectViewModel.isArabic - ? widget.item.rxMessagen.toString() - : widget.item.rxMessage.toString(), - style: TextStyle(color: Colors.red, fontSize: 10), - ) - : Container()), - ), - widget.item.rxMessage != null - ? Icon( - FontAwesomeIcons.questionCircle, - color: Colors.red, - size: 15.0, - ) - : Container(), ], ), ), diff --git a/lib/pages/pharmacies/screens/product-details/shared/icon_with_bg.dart b/lib/pages/pharmacies/screens/product-details/shared/icon_with_bg.dart index 9033cd72..f2406614 100644 --- a/lib/pages/pharmacies/screens/product-details/shared/icon_with_bg.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/icon_with_bg.dart @@ -17,12 +17,14 @@ class IconWithBg extends StatelessWidget { color: Colors.grey[200], borderRadius: BorderRadius.circular(30), ), - child: IconButton( - icon: Icon(icon), - color: color, - onPressed: () async { - onPress(); - }, + child: Center( + child: IconButton( + icon: Icon(icon, size: 20,), + color: color, + onPressed: () async { + onPress(); + }, + ), )); } } diff --git a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart index 95689326..13547fd1 100644 --- a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart @@ -43,7 +43,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { Row( children: [ IconWithBg( - icon: Icons.arrow_back_ios, + icon: Icons.arrow_back, color: Colors.grey, onPress: () { Navigator.pop(context); @@ -56,7 +56,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { children: [ IconWithBg( icon: Icons.shopping_cart, - color: Colors.grey, + color: Colors.grey[800], onPress: () { Navigator.push( context, From 92540041253d3782982852ad4f1c9d245b4f45c0 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 16:26:27 +0300 Subject: [PATCH 2/4] fix coloring issue --- .../screens/product-details/product-detail.dart | 1 + .../shared/product_details_app_bar.dart | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index f3524b35..b1bc4f4b 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -98,6 +98,7 @@ class __ProductDetailPageState extends State{ isShowDecPage: false, customAppBar: ProductAppBar( product: widget.product, + quantity: quantity, model: model, addToWishlistFunction: (item) { addToWishlistFunction(itemID:item,model:model); diff --git a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart index 13547fd1..99dfd546 100644 --- a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart @@ -20,7 +20,12 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { final Function addToWishlistFunction; final int quantity; - ProductAppBar({Key key, this.product, this.model, this.addToWishlistFunction, this.quantity}) + ProductAppBar( + {Key key, + this.product, + this.model, + this.addToWishlistFunction, + this.quantity}) : super(key: key); AuthenticatedUserObject authenticatedUserObject = @@ -71,7 +76,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { icon: FontAwesomeIcons.ellipsisV, color: Colors.grey, onPress: () { - settingModalBottomSheet(context); + settingModalBottomSheet( + context); }, ), ], @@ -84,7 +90,6 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { ); } - @override @override Size get preferredSize => Size(double.maxFinite, 50); @@ -121,8 +126,9 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { title: Text( TranslationBase.of(context).addToWishlist, ), - onTap: () => - {addToWishlistFunction(itemID: itemID, model: model)}, + onTap: () { + addToWishlistFunction(itemID: itemID, model: model); + }, ), ListTile( leading: Icon(Icons.compare), From b0b278a7e3d628eb6cd246042cd902d7005a1307 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Thu, 7 Oct 2021 09:14:48 +0300 Subject: [PATCH 3/4] fix bugs --- .../product_detail_view_model.dart | 10 +- .../pharmacies/ProductCheckTypeWidget.dart | 2 +- .../product-details/product-detail.dart | 8 +- .../screens/product-details/reviews_info.dart | 123 +++++++++--------- .../shared/product_details_app_bar.dart | 4 +- .../product_detail_service.dart | 12 +- 6 files changed, 85 insertions(+), 74 deletions(-) diff --git a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart index 9c8e7ef4..968fe029 100644 --- a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart +++ b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart @@ -97,12 +97,12 @@ class ProductDetailViewModel extends BaseViewModel{ } - Future deletWishlistData(itemID) async { + Future deleteWishlistData(itemID) async { hasError = false; setState(ViewState.BusyLocal); GifLoaderDialogUtils.showMyDialog( locator().navigatorKey.currentContext); - await _productDetailService.delteItemFromWishlist(itemID); + await _productDetailService.deleteItemFromWishlist(itemID); GifLoaderDialogUtils.hideDialog( locator().navigatorKey.currentContext); @@ -125,4 +125,10 @@ class ProductDetailViewModel extends BaseViewModel{ setState(ViewState.Idle); } + clearReview(){ + + productDetailService.clear(); + + } + } \ No newline at end of file diff --git a/lib/pages/pharmacies/ProductCheckTypeWidget.dart b/lib/pages/pharmacies/ProductCheckTypeWidget.dart index edecff62..e6139d73 100644 --- a/lib/pages/pharmacies/ProductCheckTypeWidget.dart +++ b/lib/pages/pharmacies/ProductCheckTypeWidget.dart @@ -87,7 +87,7 @@ class _ProductCheckTypeWidgetState extends State { deleteWishListItem(itemID) async { ProductDetailViewModel x = new ProductDetailViewModel(); GifLoaderDialogUtils.showMyDialog(context); - await x.deletWishlistData(itemID); + await x.deleteWishlistData(itemID); setState(() async{ await diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 8d459a92..3ef1758b 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -98,8 +98,8 @@ class __ProductDetailPageState extends State{ product: widget.product, quantity: quantity, model: model, - addToWishlistFunction: (item) { - addToWishlistFunction(itemID:item,model:model); + addToWishlistFunction: () { + addToWishlistFunction(itemID:itemID,model:model); setState(() {}); }, ), @@ -221,6 +221,8 @@ class __ProductDetailPageState extends State{ await model.getProductReviewsData( widget.product.id); GifLoaderDialogUtils.hideDialog(context); + } else { + model.clearReview(); } setState(() { isDetails = false; @@ -324,7 +326,7 @@ class __ProductDetailPageState extends State{ deleteFromWishlistFunction({itemID, ProductDetailViewModel model}) async { isInWishList = false; - await model.deletWishlistData(itemID); + await model.deleteWishlistData(itemID); } } diff --git a/lib/pages/pharmacies/screens/product-details/reviews_info.dart b/lib/pages/pharmacies/screens/product-details/reviews_info.dart index 15260071..64336d85 100644 --- a/lib/pages/pharmacies/screens/product-details/reviews_info.dart +++ b/lib/pages/pharmacies/screens/product-details/reviews_info.dart @@ -8,82 +8,83 @@ class ReviewsInfo extends StatelessWidget { final PharmacyProduct product; final ProductDetailViewModel previousModel; - const ReviewsInfo({Key key, this.product, this.previousModel}) : super(key: key); + const ReviewsInfo({Key key, this.product, this.previousModel}) + : super(key: key); @override Widget build(BuildContext context) { return previousModel.productDetailService.length != 0 && - previousModel.productDetailService[0].reviews.length != 0 + previousModel.productDetailService[0].reviews.length != 0 ? ListView.builder( - physics: ScrollPhysics(), - itemCount: previousModel.productDetailService[0].reviews.length, - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - child: Row( + physics: ScrollPhysics(), + itemCount: previousModel.productDetailService[0].reviews.length, + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: EdgeInsets.all(8.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - child: Text( - previousModel.productDetailService[0].reviews[index] - .customerId - .toString(), - style: TextStyle( - fontSize: 17, - color: Colors.grey, - fontWeight: FontWeight.w600), + child: Row( + children: [ + Container( + child: Text( + previousModel.productDetailService[0] + .reviews[index].customerId + .toString(), + style: TextStyle( + fontSize: 17, + color: Colors.grey, + fontWeight: FontWeight.w600), + ), + ), + Container( + margin: EdgeInsets.only(left: 210), + child: RatingBar.readOnly( + initialRating: previousModel + .productDetailService[0].reviews[index].rating + .toDouble(), + size: 15.0, + filledColor: Colors.yellow[700], + emptyColor: Colors.grey[500], + isHalfAllowed: true, + halfFilledIcon: Icons.star_half, + filledIcon: Icons.star, + emptyIcon: Icons.star, + ), + ), + ], ), ), + SizedBox( + height: 10, + ), Container( - margin: EdgeInsets.only(left: 210), - child: RatingBar.readOnly( - initialRating: previousModel.productDetailService[0] - .reviews[index].rating - .toDouble(), - size: 15.0, - filledColor: Colors.yellow[700], - emptyColor: Colors.grey[500], - isHalfAllowed: true, - halfFilledIcon: Icons.star_half, - filledIcon: Icons.star, - emptyIcon: Icons.star, + child: Text( + previousModel + .productDetailService[0].reviews[index].reviewText, + style: TextStyle(fontSize: 20), ), ), + SizedBox( + height: 50, + ), + Divider(height: 1, color: Colors.grey), ], ), - ), - SizedBox( - height: 10, - ), - Container( - child: Text( - previousModel.productDetailService[0].reviews[index] - .reviewText, - style: TextStyle(fontSize: 20), - ), - ), - SizedBox( - height: 50, - ), - Divider(height: 1, color: Colors.grey), - ], - ), - ); - }, - ) + ); + }, + ) : Container( - padding: EdgeInsets.all(15), - alignment: Alignment.center, - child: Text( - TranslationBase.of(context).noReviewsAvailable, - ), + padding: EdgeInsets.all(15), + alignment: Alignment.center, + child: Text( + TranslationBase.of(context).noReviewsAvailable, + ), // Text('No Reviews Available'), - ); + ); } } diff --git a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart index 99dfd546..d5fa1165 100644 --- a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart @@ -127,8 +127,8 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { TranslationBase.of(context).addToWishlist, ), onTap: () { - addToWishlistFunction(itemID: itemID, model: model); - }, + addToWishlistFunction(); + } ), ListTile( leading: Icon(Icons.compare), diff --git a/lib/services/pharmacy_services/product_detail_service.dart b/lib/services/pharmacy_services/product_detail_service.dart index 0f86df23..990b5f23 100644 --- a/lib/services/pharmacy_services/product_detail_service.dart +++ b/lib/services/pharmacy_services/product_detail_service.dart @@ -7,6 +7,7 @@ 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'; class ProductDetailService extends BaseService { bool isLogin = false; @@ -98,7 +99,7 @@ class ProductDetailService extends BaseService { }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; - AppToast.showErrorToast(message: super.error??'something went wrong please try again'); + AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); }, body: request); } @@ -109,7 +110,7 @@ class ProductDetailService extends BaseService { }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; - AppToast.showErrorToast(message: 'something went wrong please try again'); + AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); }); } @@ -126,12 +127,13 @@ class ProductDetailService extends BaseService { _wishListProducts.clear(); response['shopping_carts'].forEach((item) { _wishListProducts.add(Wishlist.fromJson(item)); - AppToast.showSuccessToast(message: 'You have added a product to the Wishlist'); }); + AppToast.showSuccessToast(message: 'You have added a product to the Wishlist'); + }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; - AppToast.showErrorToast(message: 'something went wrong please try again'); + AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); }, body: request); } @@ -149,7 +151,7 @@ class ProductDetailService extends BaseService { super.error = error; }); } - Future delteItemFromWishlist(itemID) async { + 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", From 3dc28d318a85791f23806eeb2a108e5d9e57f1c2 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Thu, 7 Oct 2021 10:16:45 +0300 Subject: [PATCH 4/4] fix bugs on wish list --- lib/config/localized_values.dart | 1 + .../product-details/product-detail.dart | 42 +++++++---- .../shared/product_details_app_bar.dart | 69 +++++++++++-------- lib/uitl/translations_delegate_base.dart | 2 + 4 files changed, 72 insertions(+), 42 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 7d764249..3979e982 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -1555,6 +1555,7 @@ const Map localizedValues = { "quantitySize": {"en": "Quantity", "ar": "كميه"}, "addToCart": {"en": "Add to Cart", "ar": "إضف للسلة"}, "addToWishlist": {"en": "Add to Wishlist", "ar": "اضف للمفضلة"}, + "removeFromWishlist": {"en": "Remove From Wishlist", "ar": "احذف للمفضلة"}, "noData": {"en": "There is no data", "ar": "لايوجد بيانات"}, "no_data": {"en": "No data", "ar": "لايوجد بيانات"}, "buyNow": {"en": "buy now", "ar": "إشتري الان"}, diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 3ef1758b..6ac5ec25 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -32,7 +32,7 @@ class ProductDetailPage extends StatefulWidget { __ProductDetailPageState createState() => __ProductDetailPageState(); } -class __ProductDetailPageState extends State{ +class __ProductDetailPageState extends State { AppSharedPreferences sharedPref = AppSharedPreferences(); bool isTrue = true; @@ -45,7 +45,6 @@ class __ProductDetailPageState extends State{ bool isInWishList = false; int quantity = 0; - checkWishlist() async { GifLoaderDialogUtils.showMyDialog(context); ProductDetailViewModel model = new ProductDetailViewModel(); @@ -98,10 +97,13 @@ class __ProductDetailPageState extends State{ product: widget.product, quantity: quantity, model: model, - addToWishlistFunction: () { - addToWishlistFunction(itemID:itemID,model:model); - setState(() {}); + addToWishlistFunction: () async { + await addToWishlistFunction(itemID: itemID, model: model); + }, + deleteFromWishlistFunction: () async { + await deleteFromWishlistFunction(itemID: itemID, model: model); }, + isInWishList:isInWishList ), body: SingleChildScrollView( child: Column( @@ -134,15 +136,19 @@ class __ProductDetailPageState extends State{ widget.product, customerId: customerId, addToWishlistFunction: (item) { - addToWishlistFunction(itemID:item,model:model); + addToWishlistFunction(itemID: item, model: model); setState(() {}); }, deleteFromWishlistFunction: (item) { - deleteFromWishlistFunction(itemID: item, model: model); + deleteFromWishlistFunction( + itemID: item, model: model); setState(() {}); }, notifyMeWhenAvailable: (context, itemId) { - notifyMeWhenAvailable(itemId:itemId, customerId: customerId, model: model); + notifyMeWhenAvailable( + itemId: itemId, + customerId: customerId, + model: model); }, isInWishList: isInWishList, ), @@ -215,12 +221,14 @@ class __ProductDetailPageState extends State{ children: [ FlatButton( onPressed: () async { - if(widget.product.approvedTotalReviews>0) { + if (widget.product.approvedTotalReviews > + 0) { GifLoaderDialogUtils.showMyDialog( context); await model.getProductReviewsData( widget.product.id); - GifLoaderDialogUtils.hideDialog(context); + GifLoaderDialogUtils.hideDialog( + context); } else { model.clearReview(); } @@ -322,21 +330,27 @@ class __ProductDetailPageState extends State{ addToWishlistFunction({itemID, ProductDetailViewModel model}) async { isInWishList = true; await model.addToWishlistData(itemID); + setState(() {}); } deleteFromWishlistFunction({itemID, ProductDetailViewModel model}) async { isInWishList = false; await model.deleteWishlistData(itemID); + setState(() {}); } } - -addToCartFunction({quantity, itemID, BuildContext context,ProductDetailViewModel model}) async { +addToCartFunction( + {quantity, + itemID, + BuildContext context, + ProductDetailViewModel model}) async { GifLoaderDialogUtils.showMyDialog(context); await model.addToCartData(quantity, itemID); GifLoaderDialogUtils.hideDialog(context); } -notifyMeWhenAvailable({itemId, customerId,ProductDetailViewModel model }) async { +notifyMeWhenAvailable( + {itemId, customerId, ProductDetailViewModel model}) async { await model.notifyMe(customerId, itemId); -} \ No newline at end of file +} diff --git a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart index d5fa1165..367e0d35 100644 --- a/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart @@ -18,14 +18,18 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { final ProductDetailViewModel model; final Function addToWishlistFunction; + final Function deleteFromWishlistFunction; final int quantity; + final bool isInWishList; ProductAppBar( {Key key, this.product, this.model, this.addToWishlistFunction, - this.quantity}) + this.quantity, + this.deleteFromWishlistFunction, + this.isInWishList}) : super(key: key); AuthenticatedUserObject authenticatedUserObject = @@ -76,8 +80,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { icon: FontAwesomeIcons.ellipsisV, color: Colors.grey, onPress: () { - settingModalBottomSheet( - context); + settingModalBottomSheet(context); }, ), ], @@ -106,38 +109,48 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { title: Text( TranslationBase.of(context).addToCart, ), - onTap: () => { - if (quantity > 0) - { - addToCartFunction( - quantity: quantity, - itemID: itemID, - context: context, - model: model) - } - else - { - AppToast.showErrorToast( - message: "you should add quantity") - } - }), + onTap: () async { + if (quantity > 0) { + { + await addToCartFunction( + quantity: quantity, + itemID: itemID, + context: context, + model: model); + + Navigator.of(context).pop(); + } + } else { + AppToast.showErrorToast( + message: "you should add quantity"); + } + }), ListTile( - leading: Icon(Icons.favorite_border), - title: Text( - TranslationBase.of(context).addToWishlist, - ), - onTap: () { - addToWishlistFunction(); - } - ), + leading: Icon( + !isInWishList ? Icons.favorite_border : Icons.favorite, + color: !isInWishList ? Colors.white : Colors.red[800], + ), + title: Text( + isInWishList + ? TranslationBase.of(context).removeFromWishlist + : TranslationBase.of(context).addToWishlist, + ), + onTap: () async { + if (isInWishList) + await deleteFromWishlistFunction(); + else + await addToWishlistFunction(); + Navigator.of(context).pop(); + }), ListTile( leading: Icon(Icons.compare), title: Text( TranslationBase.of(context).compare, ), - onTap: () => { + onTap: () { Provider.of(context, listen: false) - .addItem(specificationData), + .addItem(specificationData); + Navigator.of(context).pop(); }, ), ], diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 158d8afb..d8c3ff7b 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -1398,6 +1398,8 @@ class TranslationBase { String get addToCart => localizedValues['addToCart'][locale.languageCode]; String get addToWishlist => localizedValues['addToWishlist'][locale.languageCode]; + String get removeFromWishlist => + localizedValues['removeFromWishlist'][locale.languageCode]; String get buyNow => localizedValues['buyNow'][locale.languageCode]; String get quantityShortcut => localizedValues['quantityShortcut'][locale.languageCode];