From b0b278a7e3d628eb6cd246042cd902d7005a1307 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Thu, 7 Oct 2021 09:14:48 +0300 Subject: [PATCH] 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",