From 0d3f6237ce1fae5f64b060c62ee079b862e1224b Mon Sep 17 00:00:00 2001 From: Fatimah Alshammari Date: Wed, 11 Aug 2021 16:41:21 +0300 Subject: [PATCH] fixed issues --- lib/pages/pharmacies/product_detail.dart | 81 +++---- .../screens/recommended-product-page.dart | 225 +++++------------- 2 files changed, 87 insertions(+), 219 deletions(-) diff --git a/lib/pages/pharmacies/product_detail.dart b/lib/pages/pharmacies/product_detail.dart index 0abc38ef..72c2bd2d 100644 --- a/lib/pages/pharmacies/product_detail.dart +++ b/lib/pages/pharmacies/product_detail.dart @@ -22,6 +22,8 @@ int price = 0; var languageID; bool isOverQuantity = false; bool isInWishlit = false; +//int isSelected = 1; +bool isSelected= true; String itemID; var customerId; CompareList compareItems = new CompareList(); @@ -642,14 +644,12 @@ class __ProductDetailPageState extends State { padding: EdgeInsets.only(bottom: 5), // margin: EdgeInsets.symmetric(horizontal: 6, vertical: 4), child: BaseView( - onModelReady: (model) => - model.getRecommendedProducts( - widget.product.id.toString()), + + onModelReady: (model) => model.getRecommendedProducts(widget.product.id.toString()), builder: (_, model, wi) => Container( child: // Text(model.recommendedProductList[0].id), - model.recommendedProductList.length != - null + model.recommendedProductList.length != null ? Expanded( child: ListView.builder( scrollDirection: @@ -657,11 +657,8 @@ class __ProductDetailPageState extends State { shrinkWrap: true, physics: ScrollPhysics(), // physics: NeverScrollableScrollPhysics(), - itemCount: model - .recommendedProductList - .length, - itemBuilder: - (context, index) { + itemCount: model.recommendedProductList.length, + itemBuilder: (context, index) { return InkWell( onTap: () { Navigator.push( @@ -674,42 +671,22 @@ class __ProductDetailPageState extends State { elevation: 2, shape: RoundedRectangleBorder( side: BorderSide( - color: Colors - .grey[ - 300], + color: Colors.grey[300], width: 2), - borderRadius: - BorderRadius - .circular( - 10)), - margin: EdgeInsets - .symmetric( + borderRadius: BorderRadius.circular(10)), + margin: EdgeInsets.symmetric( horizontal: 8, vertical: 0, ), child: Container( - decoration: - BoxDecoration( - borderRadius: - BorderRadius - .all( - Radius.circular( - 15), + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(15), ), ), - padding: EdgeInsets - .symmetric( - horizontal: - 4), - width: MediaQuery.of( - context) - .size - .width / - 3, + padding: EdgeInsets.symmetric(horizontal: 4), + width: MediaQuery.of(context).size.width / 3, child: Column( - crossAxisAlignment: - CrossAxisAlignment - .start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Stack( children: [ @@ -717,11 +694,10 @@ class __ProductDetailPageState extends State { child: Align( alignment: Alignment.topRight, child: IconButton( - icon: Icon(!isInWishlit - ? Icons.favorite_border - : Icons.favorite), + icon: Icon(!isInWishlit ? Icons.favorite_border : Icons.favorite), color: !isInWishlit ? Colors.grey : Colors.red, onPressed: () async { + if (customerId != null) { if (!isInWishlit) { await addToWishlistFunction(model.recommendedProductList[index].id); @@ -734,29 +710,36 @@ class __ProductDetailPageState extends State { setState(() {}); }, )), -// itemID.contains(model.recommendedProductList[index].id) + +// child: Align( +// alignment: Alignment.topRight, +// child:itemID.contains(model.recommendedProductList[index].id) // // !isInWishlist // ? IconButton( // icon: Icon(Icons.favorite_border), -// color: Colors.red, +// color: Colors.grey, // iconSize: 30, // onPressed: () { // setState(() { -// deleteFromWishlistFunction(itemID); -// }); +// if (customerId != null && isInWishlit ) { +// deleteFromWishlistFunction( +// model.recommendedProductList[index].id); +// } }); // }, // ) // : IconButton( // icon: Icon(Icons.favorite), -// color: Colors.grey, +// color: Colors.red, // iconSize: 30, // onPressed: () { // setState(() { -// addToWishlistFunction(itemID); -// }); +// if (customerId != null && !isInWishlit ) { +// addToWishlistFunction( +// model.recommendedProductList[index].id); +// } }); // }, // ) -// +// ), ), Container( diff --git a/lib/pages/pharmacies/screens/recommended-product-page.dart b/lib/pages/pharmacies/screens/recommended-product-page.dart index 28e3cce3..28abf661 100644 --- a/lib/pages/pharmacies/screens/recommended-product-page.dart +++ b/lib/pages/pharmacies/screens/recommended-product-page.dart @@ -231,37 +231,21 @@ class _RecommendedProductPageState extends State Stack(children: [ Container( child: Align( - alignment: - Alignment - .topRight, - child: - itemID.contains(e.id) + alignment: Alignment.topRight, + child: itemID.contains(e.id) // !isInWishlist - ? IconButton( - icon: - Icon(Icons.favorite_border), - color: - Colors.grey, - iconSize: - 30, + ? IconButton(icon: Icon(Icons.favorite_border), + color: Colors.grey, iconSize: 30, onPressed: () { - setState(() { - addToWishlistFunction(itemID); + setState(() {addToWishlistFunction(itemID); }); }, ) - : - IconButton( - icon: - Icon(Icons.favorite), - color: - Colors.red, - iconSize: - 30, + : IconButton(icon: Icon(Icons.favorite), + color: Colors.red, iconSize: 30, onPressed: - () { - setState(() { + () {setState(() { deleteFromWishlistFunction(itemID); }); }, @@ -269,149 +253,74 @@ class _RecommendedProductPageState extends State // ), ), - Container( - margin: EdgeInsets - .fromLTRB(0, 16, - 10, 16), - alignment: - Alignment.center, + Container(margin: EdgeInsets.fromLTRB(0, 16, 10, 16), + alignment: Alignment.center, // padding: EdgeInsets.only(left: 25, bottom: 20), - child: (e.images != - null && - e.images.length > - 0) - ? Image.network( - e.images[0] - .src - .toString(), + child: (e.images != null && e.images.length > 0) + ? Image.network(e.images[0].src.toString(), // item.images[0].src, - fit: BoxFit - .cover, - height: 60, - ) - : Image.asset( - "assets/images/no_image.png", - fit: BoxFit - .cover, - height: 60, + fit: BoxFit.cover, height: 60,) + : Image.asset("assets/images/no_image.png", fit: BoxFit.cover, height: 60, ), ), - Container( - width: e.rxMessage != - null - ? MediaQuery.of( - context) - .size - .width / - 5 - : 0, - padding: - EdgeInsets.all(4), - decoration: - BoxDecoration( - color: Color( - 0xffb23838), - borderRadius: - BorderRadius.only( - topLeft: Radius - .circular( - 6)), + Container(width: e.rxMessage != null ? MediaQuery.of(context) + .size.width / 5 : 0, + padding: EdgeInsets.all(4), + decoration: BoxDecoration( + color: Color(0xffb23838), + borderRadius: BorderRadius.only(topLeft: Radius.circular(6)), ), - child: Texts( - e.rxMessage != null - ? e.rxMessage - : "", + child: Texts(e.rxMessage != null ? e.rxMessage : "", color: Colors.white, regular: true, fontSize: 10, - fontWeight: - FontWeight.w400, + fontWeight: FontWeight.w400, ), ), ]), Container( margin: EdgeInsets - .symmetric( - horizontal: 6, - vertical: 0, + .symmetric(horizontal: 6, vertical: 0, ), child: Column( - crossAxisAlignment: - CrossAxisAlignment - .start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - languageID == "ar" - ? e.namen - : e.name, + languageID == "ar" ? e.namen : e.name, style: TextStyle( - color: Colors - .black, - fontSize: 13.0, + color: Colors.black, fontSize: 13.0, // fontWeight: FontWeight.bold, ), ), Padding( // padding: const EdgeInsets.only(top: 15, bottom: 10), - padding: - const EdgeInsets - .only( - top: 10, - bottom: - 5), - child: Texts( - "SAR ${e.price}", - bold: true, - fontSize: 14, + padding: const EdgeInsets.only(top: 10, bottom: 5), + child: Texts("SAR ${e.price}", + bold: true, fontSize: 14, ), ), ], ), ), Row( - crossAxisAlignment: - CrossAxisAlignment - .start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - padding: EdgeInsets - .only( - right: - 10), + padding: EdgeInsets.only(right: 10), // margin: EdgeInsets.only(left: 5), - child: Align( - alignment: - Alignment - .topLeft, - child: RatingBar - .readOnly( - initialRating: e - .approvedRatingSum - .toDouble(), + child: Align(alignment: Alignment.topLeft, + child: RatingBar.readOnly(initialRating: e.approvedRatingSum.toDouble(), // initialRating: productRate, - size: 13.0, - filledColor: - Colors.yellow[ - 700], - emptyColor: - Colors.grey[ - 500], - isHalfAllowed: - true, - halfFilledIcon: - Icons - .star_half, - filledIcon: - Icons - .star, - emptyIcon: - Icons - .star, + size: 13.0, filledColor: Colors.yellow[700], + emptyColor: Colors.grey[500], + isHalfAllowed: true, + halfFilledIcon: Icons.star_half, + filledIcon: Icons.star, + emptyIcon: Icons.star, ), ), ), - Texts( - "(${e.approvedTotalReviews.toString()})", + Texts("(${e.approvedTotalReviews.toString()})", // bold: true, fontSize: 12, ), @@ -664,8 +573,7 @@ class _RecommendedProductPageState extends State return Card( elevation: 2, shape: RoundedRectangleBorder( - side: - BorderSide(color: Colors.grey[300], width: 2), + side: BorderSide(color: Colors.grey[300], width: 2), borderRadius: BorderRadius.circular(10)), // margin: EdgeInsets.symmetric( @@ -692,14 +600,12 @@ class _RecommendedProductPageState extends State //wishlistVar[index].id.contains(model.recommendedProductList[index].id) !isInWishlist ? IconButton( - icon: Icon( - Icons.favorite_border), + icon: Icon(Icons.favorite_border), color: Colors.grey, iconSize: 30, onPressed: () { setState(() { - addToWishlistFunction( - itemID); + addToWishlistFunction(itemID); }); }, ) @@ -709,8 +615,7 @@ class _RecommendedProductPageState extends State iconSize: 30, onPressed: () { setState(() { - deleteFromWishlistFunction( - itemID); + deleteFromWishlistFunction(itemID); }); }, ) @@ -721,30 +626,20 @@ class _RecommendedProductPageState extends State margin: EdgeInsets.fromLTRB(0, 16, 10, 16), alignment: Alignment.center, // padding: EdgeInsets.only(left: 25, bottom: 20), - child: (model.recommendedProductList[index] - .images != - null && - model.recommendedProductList[index] - .images.length > - 0) - ? Image.network( - model.recommendedProductList[index] - .images[0].src - .toString(), + child: (model.recommendedProductList[index].images != null && + model.recommendedProductList[index].images.length > 0) + ? Image.network(model.recommendedProductList[index].images[0].src.toString(), // item.images[0].src, fit: BoxFit.cover, height: 60, ) - : Image.asset( - "assets/images/no_image.png", + : Image.asset("assets/images/no_image.png", fit: BoxFit.cover, height: 60, ), ), Container( - width: model.recommendedProductList[index] - .rxMessage != - null + width: model.recommendedProductList[index].rxMessage != null ? MediaQuery.of(context).size.width / 5 : 0, padding: EdgeInsets.all(4), @@ -754,11 +649,8 @@ class _RecommendedProductPageState extends State topLeft: Radius.circular(6)), ), child: Texts( - model.recommendedProductList[index] - .rxMessage != - null - ? model.recommendedProductList[index] - .rxMessage + model.recommendedProductList[index].rxMessage != null + ? model.recommendedProductList[index].rxMessage : "", color: Colors.white, regular: true, @@ -773,12 +665,9 @@ class _RecommendedProductPageState extends State vertical: 2, ), child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - model - .recommendedProductList[index].name, + Text(model.recommendedProductList[index].name, style: TextStyle( color: Colors.black, fontSize: 13.0, @@ -799,8 +688,7 @@ class _RecommendedProductPageState extends State ), ), Row( - crossAxisAlignment: - CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( padding: EdgeInsets.only( @@ -809,10 +697,7 @@ class _RecommendedProductPageState extends State child: Align( alignment: Alignment.topLeft, child: RatingBar.readOnly( - initialRating: model - .recommendedProductList[index] - .approvedRatingSum - .toDouble(), + initialRating: model.recommendedProductList[index].approvedRatingSum.toDouble(), // initialRating: productRate, size: 13.0, filledColor: Colors.yellow[700],