From 11d37d26e53b658f6128cf42e0e5f6aac50b562e Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 9 Nov 2021 17:59:36 +0300 Subject: [PATCH] Product Detail page fix --- .../product-details/product-detail.dart | 394 +++++++++--------- .../product-name-and-price.dart | 2 +- .../product_detail_service.dart | 10 +- 3 files changed, 205 insertions(+), 201 deletions(-) diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 015df6ed..2676280f 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -1,4 +1,5 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; @@ -11,6 +12,7 @@ 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:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart'; import 'package:flutter/material.dart'; import 'availability_info.dart'; @@ -87,8 +89,8 @@ class __ProductDetailPageState extends State { Widget build(BuildContext context) { return BaseView( allowAny: true, - onModelReady: (model) { - model.getProductReviewsData(widget.product.id); + onModelReady: (model) async { + await model.getProductReviewsData(widget.product.id).then((value) {}); }, builder: (_, model, wi) => AppScaffold( appBarTitle: TranslationBase.of(context).productDetails, @@ -108,215 +110,219 @@ class __ProductDetailPageState extends State { isInWishList: isInWishList, addToCartFunction: addToCartFunction, ), - body: SingleChildScrollView( - child: Column( - children: [ - Container( - width: double.infinity, - color: Colors.white, + body: model.state == ViewState.Idle + ? SingleChildScrollView( child: Column( children: [ - if (widget.product.images.isNotEmpty) - Container( - height: MediaQuery.of(context).size.height * .40, - child: Image.network( - widget.product.images[0].src.trim(), - fit: BoxFit.contain, - ), + Container( + width: double.infinity, + color: Colors.white, + child: Column( + children: [ + if (widget.product.images.isNotEmpty) + Container( + height: MediaQuery.of(context).size.height * .40, + child: Image.network( + widget.product.images[0].src.trim(), + fit: BoxFit.contain, + ), + ), + if (widget.product.discountDescription != null) DiscountDescription(product: widget.product) + ], ), - if (widget.product.discountDescription != null) DiscountDescription(product: widget.product) - ], - ), - ), - SizedBox( - height: 4, - ), - Container( - color: Colors.white, - child: ProductNameAndPrice( - context, - widget.product, - customerId: customerId, - addToWishlistFunction: (item) { - addToWishlistFunction(itemID: item, model: model); - setState(() {}); - }, - deleteFromWishlistFunction: (item) { - deleteFromWishlistFunction(itemID: item, model: model); - setState(() {}); - }, - notifyMeWhenAvailable: (context, itemId) { - notifyMeWhenAvailable(itemId: itemId, customerId: customerId, model: model); - }, - isInWishList: isInWishList, - isStockAvailable: model.isStockAvailable, - ), - ), - SizedBox( - height: 6, - ), - Container( - color: Colors.white, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ + ), + SizedBox( + height: 4, + ), Container( - padding: EdgeInsets.symmetric(vertical: 15, horizontal: 10), - child: Texts( - TranslationBase.of(context).specification, - fontSize: 15, - fontWeight: FontWeight.bold, + color: Colors.white, + child: ProductNameAndPrice( + context, + widget.product, + customerId: customerId, + addToWishlistFunction: (item) { + addToWishlistFunction(itemID: item, model: model); + setState(() {}); + }, + deleteFromWishlistFunction: (item) { + deleteFromWishlistFunction(itemID: item, model: model); + setState(() {}); + }, + notifyMeWhenAvailable: (context, itemId) { + notifyMeWhenAvailable(itemId: itemId, customerId: customerId, model: model); + }, + isInWishList: isInWishList, + isStockAvailable: model.isStockAvailable, ), - width: double.infinity, ), - // Divider(color: Colors.grey), - ], - ), - ), - SizedBox( - height: 6, - ), - Container( - // width: 500, - margin: EdgeInsets.only(bottom: 6), - color: Colors.white, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Column( - children: [ - FlatButton( - onPressed: () { - setState(() { - isDetails = true; - isReviews = false; - isAvailability = false; - }); - }, - child: Text( - TranslationBase.of(context).details, - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), - ), - color: Colors.white, + SizedBox( + height: 6, + ), + Container( + color: Colors.white, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: EdgeInsets.symmetric(vertical: 15, horizontal: 10), + child: Texts( + TranslationBase.of(context).specification, + fontSize: 15, + fontWeight: FontWeight.bold, ), - CustomDivider( - color: isDetails ? Colors.green : Colors.transparent, - ) - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () async { - if (widget.product.approvedTotalReviews > 0) { - GifLoaderDialogUtils.showMyDialog(context); - await model.getProductReviewsData(widget.product.id); - GifLoaderDialogUtils.hideDialog(context); - } else { - model.clearReview(); - } - setState(() { - isDetails = false; - isReviews = true; - isAvailability = false; - }); - }, - child: Text( - TranslationBase.of(context).reviews, - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + width: double.infinity, + ), + // Divider(color: Colors.grey), + ], + ), + ), + SizedBox( + height: 6, + ), + Container( + // width: 500, + margin: EdgeInsets.only(bottom: 6), + color: Colors.white, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Column( + children: [ + FlatButton( + onPressed: () { + setState(() { + isDetails = true; + isReviews = false; + isAvailability = false; + }); + }, + child: Text( + TranslationBase.of(context).details, + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + color: Colors.white, + ), + CustomDivider( + color: isDetails ? Colors.green : Colors.transparent, + ) + ], ), - color: Colors.white, - ), - CustomDivider( - color: isReviews ? Colors.green : Colors.transparent, - ), - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () async { - GifLoaderDialogUtils.showMyDialog(context); - await model.getProductLocationData(); - GifLoaderDialogUtils.hideDialog(context); + SizedBox( + width: 20, + ), + Column( + children: [ + FlatButton( + onPressed: () async { + if (widget.product.approvedTotalReviews > 0) { + GifLoaderDialogUtils.showMyDialog(context); + await model.getProductReviewsData(widget.product.id); + GifLoaderDialogUtils.hideDialog(context); + } else { + model.clearReview(); + } + setState(() { + isDetails = false; + isReviews = true; + isAvailability = false; + }); + }, + child: Text( + TranslationBase.of(context).reviews, + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + color: Colors.white, + ), + CustomDivider( + color: isReviews ? Colors.green : Colors.transparent, + ), + ], + ), + SizedBox( + width: 20, + ), + Column( + children: [ + FlatButton( + onPressed: () async { + GifLoaderDialogUtils.showMyDialog(context); + await model.getProductLocationData(); + GifLoaderDialogUtils.hideDialog(context); - setState(() { - isDetails = false; - isReviews = false; - isAvailability = true; - }); - }, - child: Text( - TranslationBase.of(context).availability, - style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + setState(() { + isDetails = false; + isReviews = false; + isAvailability = true; + }); + }, + child: Text( + TranslationBase.of(context).availability, + style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + color: Colors.white, + ), + CustomDivider( + color: isAvailability ? Colors.green : Colors.transparent, + ), + ], ), - color: Colors.white, - ), - CustomDivider( - color: isAvailability ? Colors.green : Colors.transparent, - ), - ], - ), - ], + ], + ), + SizedBox( + height: 10, + ), + isDetails + ? DetailsInfo( + product: widget.product, + ) + : isReviews + ? ReviewsInfo( + product: widget.product, + previousModel: model, + ) + : isAvailability + ? AvailabilityInfo( + previousModel: model, + ) + : Container(), + ], + ), ), SizedBox( height: 10, ), - isDetails - ? DetailsInfo( - product: widget.product, - ) - : isReviews - ? ReviewsInfo( - product: widget.product, - previousModel: model, - ) - : isAvailability - ? AvailabilityInfo( - previousModel: model, - ) - : Container(), + RecommendedProducts( + product: widget.product, + productDetailViewModel: model, + addToWishlistFunction: (itemID) async { + await addToWishlistFunction(itemID: itemID, model: model); + }, + deleteFromWishlistFunction: (itemID) async { + await deleteFromWishlistFunction(itemID: itemID, model: model); + }, + ) ], ), - ), - SizedBox( - height: 10, - ), - RecommendedProducts( - product: widget.product, - productDetailViewModel: model, - addToWishlistFunction: (itemID) async { - await addToWishlistFunction(itemID: itemID, model: model); - }, - deleteFromWishlistFunction: (itemID) async { - await deleteFromWishlistFunction(itemID: itemID, model: model); - }, ) - ], - ), - ), - bottomSheet: FooterWidget( - model.isStockAvailable, - widget.product.orderMaximumQuantity, - widget.product.orderMinimumQuantity, - model.stockQuantity, - widget.product, - quantity: quantity, - isOverQuantity: isOverQuantity, - addToCartFunction: addToCartFunction, - addToShoppingCartFunction: addToShoppingCartFunction, - model: model, - ), + : AppCircularProgressIndicator(), + bottomSheet: model.state == ViewState.Idle + ? FooterWidget( + model.isStockAvailable, + widget.product.orderMaximumQuantity, + widget.product.orderMinimumQuantity, + model.stockQuantity, + widget.product, + quantity: quantity, + isOverQuantity: isOverQuantity, + addToCartFunction: addToCartFunction, + addToShoppingCartFunction: addToShoppingCartFunction, + model: model, + ) + : 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 9401f3e0..e214d70e 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 @@ -24,7 +24,7 @@ class ProductNameAndPrice extends StatefulWidget { AuthenticatedUserObject authenticatedUserObject = locator(); ProductNameAndPrice(this.context, this.item, - {this.customerId, this.isInWishList, this.notifyMeWhenAvailable, this.addToWishlistFunction, this.deleteFromWishlistFunction, @required this.isStockAvailable}); + {this.customerId, this.isInWishList, this.notifyMeWhenAvailable, this.addToWishlistFunction, this.deleteFromWishlistFunction, this.isStockAvailable = false}); @override _ProductNameAndPriceState createState() => _ProductNameAndPriceState(); diff --git a/lib/services/pharmacy_services/product_detail_service.dart b/lib/services/pharmacy_services/product_detail_service.dart index 23379914..795530ff 100644 --- a/lib/services/pharmacy_services/product_detail_service.dart +++ b/lib/services/pharmacy_services/product_detail_service.dart @@ -2,15 +2,11 @@ import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/service/base_service.dart'; import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart'; -import 'package:diplomaticquarterapp/models/pharmacy/addToCartModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart'; 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'; -import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/utils.dart'; class ProductDetailService extends BaseService { bool isLogin = false; @@ -57,7 +53,9 @@ class ProductDetailService extends BaseService { }); _stockQuantity = response['products'][0]['stock_quantity']; _stockAvailability = response['products'][0]['stock_availability']; - _isStockAvailable = response['products'][0]['IsStockAvailable']; + + // _isStockAvailable = response['products'][0]['IsStockAvailable']; + _isStockAvailable = _stockAvailability == "In stock" ? true : false; }, onFailure: (String error, int statusCode) { hasError = true; super.error = error;