From 7c15bca7465760e5fcb895f61dc6372eeb02f68f Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Tue, 5 Oct 2021 16:24:42 +0300 Subject: [PATCH 01/15] fix item --- .../screens/product-details/CustomIcon.dart | 4 +- .../product-details/ProductAppBar.dart | 139 ++++++++++++------ .../product-details/footor/footer-widget.dart | 5 +- .../product-details/product-detail.dart | 16 +- .../product-name-and-price.dart | 2 +- 5 files changed, 115 insertions(+), 51 deletions(-) diff --git a/lib/pages/pharmacies/screens/product-details/CustomIcon.dart b/lib/pages/pharmacies/screens/product-details/CustomIcon.dart index c9a71afa..fc8b2288 100644 --- a/lib/pages/pharmacies/screens/product-details/CustomIcon.dart +++ b/lib/pages/pharmacies/screens/product-details/CustomIcon.dart @@ -11,11 +11,11 @@ class IconWithBg extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.only(left: 25), + // margin: EdgeInsets.only(left: 25), width: 40, height: 40, decoration: BoxDecoration( - color: Colors.grey[300], + color: Colors.grey[200], borderRadius: BorderRadius.circular(30), ), child: IconButton( diff --git a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart index 36c43364..c895d7c9 100644 --- a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart +++ b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart @@ -1,6 +1,11 @@ +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:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:provider/provider.dart'; +import '../../compare-list.dart'; import '../cart-order-page.dart'; import 'CustomIcon.dart'; @@ -9,58 +14,108 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { Widget build(BuildContext context) { return Container( color: Colors.white, - child: Column( - children: [ - SizedBox( - height: 30, - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - IconWithBg( - icon: Icons.arrow_back_ios, - color: Colors.grey, - onPress: () { - Navigator.pop(context); - }, - ), - ], - ), - Row( - children: [ - IconWithBg( - icon: Icons.shopping_cart, + + child: FractionallySizedBox( + widthFactor: 0.95, + child: Column( + children: [ + SizedBox( + height: 30, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + IconWithBg( + icon: Icons.arrow_back_ios, color: Colors.grey, onPress: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => CartOrderPage()), - ); - }), - IconWithBg( - icon: FontAwesomeIcons.ellipsisV, - color: Colors.grey, - onPress: () { - //TODO Elham* - // settingModalBottomSheet(context); - }, - ), - ], - ) - ], - ), - ], + Navigator.pop(context); + }, + ), + ], + ), + Row( + children: [ + IconWithBg( + icon: Icons.shopping_cart, + color: Colors.grey, + onPress: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => CartOrderPage()), + ); + }), + SizedBox(width: 10,), + IconWithBg( + icon: FontAwesomeIcons.ellipsisV, + color: Colors.grey, + onPress: () { + settingModalBottomSheet(context); + }, + ), + ], + ) + ], + ), + ], + ), ), ); } + + @override // TODO: implement preferredSize @override Size get preferredSize => Size(double.maxFinite, 50); + + settingModalBottomSheet(context) { + showModalBottomSheet( + context: context, + builder: (BuildContext bc) { + return Container( + child: new Wrap( + children: [ + new ListTile( + leading: Icon(Icons.shopping_cart), + title: Text( + TranslationBase.of(context).addToCart, + ), + onTap: () => { + if (price > 0) + {addToCartFunction(price, itemID, context)} + else + { + AppToast.showErrorToast( + message: "you should add quantity") + } + }), + ListTile( + leading: Icon(Icons.favorite_border), + title: Text( + TranslationBase.of(context).addToWishlist, + ), + onTap: () => {addToWishlistFunction(itemID)}, + ), + ListTile( + leading: Icon(Icons.compare), + title: Text( + TranslationBase.of(context).compare, + ), + onTap: () => { + Provider.of(context, listen: false) + .addItem(specificationData), + }, + ), + ], + ), + ); + }); + } } 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 cca4eef5..88302480 100644 --- a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart +++ b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart @@ -178,7 +178,7 @@ class _FooterWidgetState extends State { ), ), Container( - width: MediaQuery.of(context).size.width * 0.4, + width: MediaQuery.of(context).size.width * 0.45, child: SecondaryButton( label: TranslationBase.of(context).addToCart.toUpperCase(), disabled: !widget.isAvailable && widget.price > 0 || @@ -188,6 +188,7 @@ class _FooterWidgetState extends State { widget.addToCartFunction( widget.price, widget.item.id, context); }, + borderRadius: 5, color: Colors.green, ), @@ -196,7 +197,7 @@ class _FooterWidgetState extends State { width: 5, ), Container( - width: MediaQuery.of(context).size.width * 0.3, + width: MediaQuery.of(context).size.width * 0.35, child: SecondaryButton( label: TranslationBase.of(context).buyNow.toUpperCase(), disabled: !widget.isAvailable && widget.price > 0 || diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 08a622aa..d2ce4f35 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -112,7 +112,7 @@ class __ProductDetailPageState extends State isShowAppBar: true, isPharmacy: true, isShowDecPage: false, - customAppBar: ProductAppBar(), + customAppBar: ProductAppBar(), body: SingleChildScrollView( child: Column( children: [ @@ -143,9 +143,17 @@ class __ProductDetailPageState extends State context, widget.product, customerId: customerId, - addToWishlistFunction: addToWishlistFunction, - deleteFromWishlistFunction: deleteFromWishlistFunction, - notifyMeWhenAvailable: notifyMeWhenAvailable, + addToWishlistFunction: (item) { + addToWishlistFunction(item); + setState(() {}); + }, + deleteFromWishlistFunction: (item) { + deleteFromWishlistFunction(item); + setState(() {}); + }, + notifyMeWhenAvailable: (context, itemId) { + notifyMeWhenAvailable(context, itemId); + }, isInWishList: isInWishList, ), ), 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 4f607e48..b7906b78 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 @@ -46,7 +46,7 @@ class _ProductNameAndPriceState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Texts(widget.item.price.toString() + " " + "SAR", + Texts(widget.item.price.toString() + " " + "SR", fontWeight: FontWeight.bold, fontSize: 20), Texts( projectViewModel.isArabic From 338901d4238592f264d03f275b6e875f93ad04a5 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Tue, 5 Oct 2021 16:29:56 +0300 Subject: [PATCH 02/15] remove add to cart --- .../pharmacies/screens/product-details/ProductAppBar.dart | 7 +++++++ .../pharmacies/screens/product-details/product-detail.dart | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart index c895d7c9..09d595f7 100644 --- a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart +++ b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart @@ -1,3 +1,4 @@ +import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.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'; @@ -10,6 +11,11 @@ import '../cart-order-page.dart'; import 'CustomIcon.dart'; class ProductAppBar extends StatelessWidget with PreferredSizeWidget { + + final PharmacyProduct product; + + const ProductAppBar({Key key, this.product}) : super(key: key); + @override Widget build(BuildContext context) { return Container( @@ -80,6 +86,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { return Container( child: new Wrap( children: [ + if( product.stockAvailability != 'Out of stock') new ListTile( leading: Icon(Icons.shopping_cart), title: Text( diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index d2ce4f35..d9c623f9 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -58,7 +58,6 @@ class __ProductDetailPageState extends State bool isDetails = true; bool isReviews = false; bool isAvailability = false; - int _activeTab = 0; checkWishlist() async { GifLoaderDialogUtils.showMyDialog(context); @@ -112,7 +111,7 @@ class __ProductDetailPageState extends State isShowAppBar: true, isPharmacy: true, isShowDecPage: false, - customAppBar: ProductAppBar(), + customAppBar: ProductAppBar(product: widget.product,), body: SingleChildScrollView( child: Column( children: [ From a5751f0d7065f7e428bf9109dc73aa09d78bdcc8 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Tue, 5 Oct 2021 17:20:38 +0300 Subject: [PATCH 03/15] handel un login cases --- .../pharmacies/screens/cart-order-page.dart | 2 + .../product-details/ProductAppBar.dart | 8 +- .../product-details/footor/footer-widget.dart | 18 +- .../product-details/product-detail.dart | 497 +----------------- .../product-name-and-price.dart | 6 + 5 files changed, 32 insertions(+), 499 deletions(-) diff --git a/lib/pages/pharmacies/screens/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-order-page.dart index c2ebf4b2..3877ce29 100644 --- a/lib/pages/pharmacies/screens/cart-order-page.dart +++ b/lib/pages/pharmacies/screens/cart-order-page.dart @@ -36,6 +36,8 @@ class CartOrderPage extends StatelessWidget { appBarTitle: TranslationBase.of(context).shoppingCart, isShowAppBar: true, isPharmacy: true, + isShowDecPage: true, + description: "", baseViewModel: model, backgroundColor: Colors.white, body: !(model.cartResponse.shoppingCarts == null || diff --git a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart index 09d595f7..2fad8016 100644 --- a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart +++ b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart @@ -1,4 +1,5 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; +import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.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'; @@ -6,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; +import '../../../../locator.dart'; import '../../compare-list.dart'; import '../cart-order-page.dart'; import 'CustomIcon.dart'; @@ -14,7 +16,10 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { final PharmacyProduct product; - const ProductAppBar({Key key, this.product}) : super(key: key); + ProductAppBar({Key key, this.product}) : super(key: key); + + AuthenticatedUserObject authenticatedUserObject = + locator(); @override Widget build(BuildContext context) { @@ -42,6 +47,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { ), ], ), + if(authenticatedUserObject.isLogin) Row( children: [ IconWithBg( 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 88302480..3ecf4b83 100644 --- a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart +++ b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart @@ -1,4 +1,8 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; +import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; +import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; +import 'package:diplomaticquarterapp/pages/login/login.dart'; +import 'package:diplomaticquarterapp/pages/login/welcome.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/footor/quantity_box.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; @@ -6,6 +10,8 @@ import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; +import '../../../../../locator.dart'; +import '../../../../../routes.dart'; import '../../cart-order-page.dart'; class FooterWidget extends StatefulWidget { @@ -30,6 +36,8 @@ class FooterWidget extends StatefulWidget { class _FooterWidgetState extends State { double quantityUI = 70; bool showUI = false; + AuthenticatedUserObject authenticatedUserObject = + locator(); @override Widget build(BuildContext context) { @@ -185,10 +193,14 @@ class _FooterWidgetState extends State { widget.price > widget.quantityLimit || widget.item.rxMessage != null, onTap: () { - widget.addToCartFunction( - widget.price, widget.item.id, context); + if (!authenticatedUserObject.isLogin) { + Navigator.of(context).pushNamed( + WELCOME_LOGIN, + ); + } else + widget.addToCartFunction( + widget.price, widget.item.id, context); }, - borderRadius: 5, color: Colors.green, ), diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index d9c623f9..5e8f4dd5 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -105,8 +105,7 @@ class __ProductDetailPageState extends State ProjectViewModel projectViewModel = Provider.of(context); final screenSize = MediaQuery.of(context).size; - return customerId != null - ? AppScaffold( + return AppScaffold( appBarTitle: TranslationBase.of(context).productDetails, isShowAppBar: true, isPharmacy: true, @@ -399,500 +398,8 @@ class __ProductDetailPageState extends State isOverQuantity: isOverQuantity, addToCartFunction: addToCartFunction, ), - ) - : AppScaffold( - appBarTitle: TranslationBase.of(context).productDetails, - isShowAppBar: true, - isPharmacy: true, - isShowDecPage: false, - showPharmacyCart: false, - showHomeAppBarIcon: false, - body: SingleChildScrollView( - child: Column( - children: [ - Container( - width: double.infinity, - color: Colors.white, - child: Column( - children: [ - Image.network( - widget.product.images[0].src.trim(), - ), - widget.product.discountDescription != null - ? Container( - width: double.infinity, - height: 50, - color: Colors.yellowAccent, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - flex: 1, - child: Container( - alignment: Alignment.centerRight, - child: projectViewModel.isArabic - ? Text( - widget.product - .discountDescriptionn, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 17), - ) - : Text( - widget.product - .discountDescription, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 17), - ), - ), - ), - SizedBox( - width: 10, - ), - Expanded( - flex: 0, - child: Container( - child: Image( - image: AssetImage( - 'assets/images/offer.png'), - ), - ), - ), - ], - ), - ) - : Container(), - ], - ), - ), - SizedBox( - height: 4, - ), - Container( - width: 500, - height: 150, - color: Colors.white, - child: ProductNameAndPrice( - context, - widget.product, - customerId: customerId, - addToWishlistFunction: addToWishlistFunction, - deleteFromWishlistFunction: deleteFromWishlistFunction, - notifyMeWhenAvailable: notifyMeWhenAvailable, - isInWishList: isInWishList, - ), - ), - SizedBox( - height: 6, - ), - Container( - width: 500, - height: 120, - color: Colors.white, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - child: Container( - child: Text( - TranslationBase.of(context).specification, - style: TextStyle(fontWeight: FontWeight.bold), - ), - ), - ), - Divider(color: Colors.grey) - ], - ), - ), - SizedBox( - height: 6, - ), - Container( - width: 500, - margin: EdgeInsets.only(bottom: 100), -// height: 350, - color: Colors.white, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - 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, - ), - isDetails - ? Container( - width: 100, - height: 5, - color: Colors.green, - ) - : Container() - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () { - setState(() { - isDetails = false; - isReviews = true; - isAvailability = false; - }); - }, - child: Text( - TranslationBase.of(context).reviews, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold), - ), - color: Colors.white, - ), - isReviews - ? Container( - width: 100, - height: 5, - color: Colors.green, - ) - : Container(), - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () { - setState(() { - isDetails = false; - isReviews = false; - isAvailability = true; - }); - }, - child: Text( - TranslationBase.of(context).availability, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold), - ), - color: Colors.white, - ), - isAvailability - ? Container( - width: 100, - height: 5, - color: Colors.green, - ) - : Container(), - ], - ), - ], - ), - SizedBox( - height: 10, - ), - isDetails - ? Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - child: Text( - TranslationBase.of(context).description, - style: TextStyle( - fontSize: 17, - color: Colors.grey, - fontWeight: FontWeight.w600), - ), - ), - SizedBox( - height: 6, - ), - Divider(height: 1, color: Colors.grey), - SizedBox( - height: 10, - ), - Container( - child: Text( - projectViewModel.isArabic - ? widget.product.shortDescriptionn - : widget.product.shortDescription, - style: TextStyle( - fontSize: 16, - fontFamily: 'WorkSans-Regular'), - ), - ), - SizedBox( - height: 10, - ), - Container( - child: Text( - TranslationBase.of(context).howToUse, - style: TextStyle( - fontSize: 17, - color: Colors.grey, - fontWeight: FontWeight.w600), - ), - ), - SizedBox( - height: 6, - ), - Divider(height: 2, color: Colors.grey), - SizedBox( - height: 10, - ), - Container( - child: Text( - projectViewModel.isArabic - ? widget.product.fullDescriptionn - : widget.product.fullDescription, - style: TextStyle( - fontSize: 16, - fontFamily: 'WorkSans-Regular'), - ), - ), - ], - ), - ) - : isReviews - ? BaseView( - onModelReady: (model) => - model.getProductReviewsData( - widget.product.id), - builder: (_, model, wi) => model - .productDetailService - .length != - 0 && - model.productDetailService[0] - .reviews.length != - 0 - ? ListView.builder( - physics: ScrollPhysics(), - itemCount: model - .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( - children: [ - Container( - child: Text( - model - .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: model - .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( - child: Text( - model - .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), - ), - ) - : isAvailability - ? BaseView( - onModelReady: (model) => - model.getProductLocationData(), - builder: (_, model, wi) => - ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: model - .productLocationService.length, - itemBuilder: (BuildContext context, - int index) { - return Padding( - padding: EdgeInsets.all(8.0), - child: Column( - children: [ - Row( - mainAxisAlignment: - MainAxisAlignment.start, - children: [ - Expanded( - flex: 1, - child: Image.network(model - .productLocationService[ - index] - .projectImageUrl), - ), - SizedBox( - width: 10, - ), - Expanded( - flex: 4, - child: Text( - model - .productLocationService[ - index] - .locationDescription + - "\n" + - convertCityName( - model - .productLocationService[ - 0] - .cityName - .toString(), - ), - style: TextStyle( - fontSize: 12), - ), - ), - Expanded( - flex: 1, - child: IconButton( - icon: Icon(Icons - .location_on), - color: Colors.red, - onPressed: () {}, - ), - ), - Expanded( - flex: 1, - child: IconButton( - icon: - Icon(Icons.phone), - color: Colors.red, - onPressed: () {}, - ), - ), - ], - ), - Divider( - height: 1.2, - color: Colors.grey) - ], - ), - ); - }, - ), - ) - : Container(), - ], - ), - ), - ], - ), - ), - bottomSheet: FooterWidget( - widget.product.stockAvailability != 'Out of stock', - widget.product.orderMaximumQuantity, - widget.product.orderMinimumQuantity, - widget.product.stockQuantity, - widget.product, - price: price, - isOverQuantity: isOverQuantity, - addToCartFunction: addToCartFunction, - ), ); + } } 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 b7906b78..619a4fb1 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 @@ -1,4 +1,5 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; +import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; @@ -8,6 +9,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import 'package:rating_bar/rating_bar.dart'; +import '../../../../locator.dart'; import 'CustomIcon.dart'; class ProductNameAndPrice extends StatefulWidget { @@ -19,6 +21,9 @@ class ProductNameAndPrice extends StatefulWidget { final Function addToWishlistFunction; final Function deleteFromWishlistFunction; + AuthenticatedUserObject authenticatedUserObject = + locator(); + ProductNameAndPrice(this.context, this.item, {this.customerId, this.isInWishList, @@ -59,6 +64,7 @@ class _ProductNameAndPriceState extends State { : Colors.green, ), // SizedBox(width: 20), + if(widget.authenticatedUserObject.isLogin) widget.item.stockAvailability == 'Out of stock' && widget.customerId != null ? InkWell( From 1e1e230908b0c713e31620e9b173ffd003b9e66e Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Tue, 5 Oct 2021 17:42:08 +0300 Subject: [PATCH 04/15] fix call service in case not login --- .../pharmacies/screens/product-details/availability_info.dart | 2 +- lib/pages/pharmacies/screens/product-details/reviews_info.dart | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pages/pharmacies/screens/product-details/availability_info.dart b/lib/pages/pharmacies/screens/product-details/availability_info.dart index 0c00d22a..55d2468c 100644 --- a/lib/pages/pharmacies/screens/product-details/availability_info.dart +++ b/lib/pages/pharmacies/screens/product-details/availability_info.dart @@ -10,7 +10,7 @@ class AvailabilityInfo extends StatelessWidget { Widget build(BuildContext context) { return BaseView( onModelReady: (model) => model.getProductLocationData(), - + allowAny: true, builder: (_, model, wi) => NetworkBaseView( baseViewModel: model, child: model.productLocationService.length == 0 diff --git a/lib/pages/pharmacies/screens/product-details/reviews_info.dart b/lib/pages/pharmacies/screens/product-details/reviews_info.dart index ed1970cd..c48e249f 100644 --- a/lib/pages/pharmacies/screens/product-details/reviews_info.dart +++ b/lib/pages/pharmacies/screens/product-details/reviews_info.dart @@ -15,6 +15,7 @@ class ReviewsInfo extends StatelessWidget { Widget build(BuildContext context) { return BaseView( onModelReady: (model) => model.getProductReviewsData(product.id), + allowAny: true, builder: (_, model, wi) => NetworkBaseView( baseViewModel:model , child: model.productDetailService.length != 0 && From 47e19c4ab5ecfa0aed24d0eb2cc39905231f834d Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 11:06:10 +0300 Subject: [PATCH 05/15] add loader and cache on images --- .../product_detail_view_model.dart | 2 +- .../product-details/availability_info.dart | 136 +++-- .../product-details/discount_description.dart | 1 - .../product-details/footor/footer-widget.dart | 3 - .../product-details/product-detail.dart | 502 ++++++++---------- .../product-name-and-price.dart | 2 +- .../screens/product-details/reviews_info.dart | 146 +++-- .../icon_with_bg.dart} | 1 - .../product_details_app_bar.dart} | 8 +- 9 files changed, 354 insertions(+), 447 deletions(-) rename lib/pages/pharmacies/screens/product-details/{CustomIcon.dart => shared/icon_with_bg.dart} (93%) rename lib/pages/pharmacies/screens/product-details/{ProductAppBar.dart => shared/product_details_app_bar.dart} (96%) diff --git a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart index c7ac0a04..2b1d3f86 100644 --- a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart +++ b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart @@ -36,7 +36,7 @@ class ProductDetailViewModel extends BaseViewModel{ Future getProductLocationData() async { hasError = false; - setState(ViewState.Busy); + setState(ViewState.BusyLocal); await _productDetailService.getProductAvailabiltyDetail(); if (_productDetailService.hasError) { error = _productDetailService.error; diff --git a/lib/pages/pharmacies/screens/product-details/availability_info.dart b/lib/pages/pharmacies/screens/product-details/availability_info.dart index 55d2468c..6a6fdfd5 100644 --- a/lib/pages/pharmacies/screens/product-details/availability_info.dart +++ b/lib/pages/pharmacies/screens/product-details/availability_info.dart @@ -6,80 +6,76 @@ import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:flutter/material.dart'; class AvailabilityInfo extends StatelessWidget { + final ProductDetailViewModel previousModel; + + const AvailabilityInfo({Key key, this.previousModel}) : super(key: key); @override Widget build(BuildContext context) { - return BaseView( - onModelReady: (model) => model.getProductLocationData(), - allowAny: true, - builder: (_, model, wi) => NetworkBaseView( - baseViewModel: model, - child: model.productLocationService.length == 0 - ? Container( - padding: EdgeInsets.all(15), - alignment: Alignment.center, - child: Text( - TranslationBase.of(context).noLocationAvailable, - ), - ) - : ListView.builder( - physics: ScrollPhysics(), - scrollDirection: Axis.vertical, - shrinkWrap: true, - itemCount: model.productLocationService.length, - itemBuilder: (BuildContext context, int index) { - return Padding( - padding: EdgeInsets.all(8.0), - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - flex: 1, - child: Image.network(model - .productLocationService[index].projectImageUrl), - ), - SizedBox( - width: 10, - ), - Expanded( - flex: 4, - child: Text( - model.productLocationService[index] - .locationDescription + - "\n" + - convertCityName( - model.productLocationService[0].cityName - .toString(), - ), - style: TextStyle(fontSize: 12), - ), - ), - Expanded( - flex: 1, - child: IconButton( - icon: Icon(Icons.location_on), - color: Colors.red, - onPressed: () {}, - ), - ), - Expanded( - flex: 1, - child: IconButton( - icon: Icon(Icons.phone), - color: Colors.red, - onPressed: () {}, - ), - ), - ], - ), - Divider(height: 1.2, color: Colors.grey) - ], + return previousModel.productLocationService.length == 0 + ? Container( + padding: EdgeInsets.all(15), + alignment: Alignment.center, + child: Text( + TranslationBase.of(context).noLocationAvailable, + ), + ) + : ListView.builder( + physics: ScrollPhysics(), + scrollDirection: Axis.vertical, + shrinkWrap: true, + itemCount: previousModel.productLocationService.length, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: EdgeInsets.all(8.0), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + flex: 1, + child: Image.network(previousModel + .productLocationService[index].projectImageUrl), + ), + SizedBox( + width: 10, + ), + Expanded( + flex: 4, + child: Text( + previousModel.productLocationService[index] + .locationDescription + + "\n" + + convertCityName( + previousModel.productLocationService[0].cityName + .toString(), + ), + style: TextStyle(fontSize: 12), + ), + ), + Expanded( + flex: 1, + child: IconButton( + icon: Icon(Icons.location_on), + color: Colors.red, + onPressed: () {}, ), - ); - }, + ), + Expanded( + flex: 1, + child: IconButton( + icon: Icon(Icons.phone), + color: Colors.red, + onPressed: () {}, + ), + ), + ], ), - ), + Divider(height: 1.2, color: Colors.grey) + ], + ), + ); + }, ); } } diff --git a/lib/pages/pharmacies/screens/product-details/discount_description.dart b/lib/pages/pharmacies/screens/product-details/discount_description.dart index 1c2b27d4..1dde8175 100644 --- a/lib/pages/pharmacies/screens/product-details/discount_description.dart +++ b/lib/pages/pharmacies/screens/product-details/discount_description.dart @@ -1,5 +1,4 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; -import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:flutter/material.dart'; class DiscountDescription extends StatelessWidget { 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 3ecf4b83..7cdfe7f2 100644 --- a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart +++ b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart @@ -1,8 +1,5 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; -import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; -import 'package:diplomaticquarterapp/pages/login/login.dart'; -import 'package:diplomaticquarterapp/pages/login/welcome.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/footor/quantity_box.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 5e8f4dd5..c263f77a 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -25,7 +25,7 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_mo import '../cart-order-page.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; -import 'ProductAppBar.dart'; +import 'shared/product_details_app_bar.dart'; import 'availability_info.dart'; import 'details_info.dart'; import 'discount_description.dart'; @@ -102,304 +102,228 @@ class __ProductDetailPageState extends State } Widget build(BuildContext context) { - ProjectViewModel projectViewModel = Provider.of(context); - final screenSize = MediaQuery.of(context).size; - - return AppScaffold( - appBarTitle: TranslationBase.of(context).productDetails, - isShowAppBar: true, - isPharmacy: true, - isShowDecPage: false, - customAppBar: ProductAppBar(product: widget.product,), - body: SingleChildScrollView( - child: Column( - children: [ - 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, + return BaseView( + allowAny: true, + builder: (_, model, wi) => AppScaffold( + appBarTitle: TranslationBase.of(context).productDetails, + isShowAppBar: true, + isPharmacy: true, + isShowDecPage: false, + customAppBar: ProductAppBar( + product: widget.product, + ), + body: SingleChildScrollView( + child: Column( + children: [ + 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(item); - setState(() {}); - }, - deleteFromWishlistFunction: (item) { - deleteFromWishlistFunction(item); - setState(() {}); - }, - notifyMeWhenAvailable: (context, itemId) { - notifyMeWhenAvailable(context, itemId); - }, - isInWishList: isInWishList, + SizedBox( + height: 4, ), - ), - 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, + Container( + color: Colors.white, + child: ProductNameAndPrice( + context, + widget.product, + customerId: customerId, + addToWishlistFunction: (item) { + addToWishlistFunction(item); + setState(() {}); + }, + deleteFromWishlistFunction: (item) { + deleteFromWishlistFunction(item); + setState(() {}); + }, + notifyMeWhenAvailable: (context, itemId) { + notifyMeWhenAvailable(context, itemId); + }, + isInWishList: isInWishList, + ), + ), + 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, + ), + width: double.infinity, ), - width: double.infinity, - ), - // Divider(color: Colors.grey), - ], + // Divider(color: Colors.grey), + ], + ), ), - ), - SizedBox( - height: 6, - ), - // Container( - // height: 500, - // color: Colors.white, - // child: Scaffold( - // backgroundColor: Colors.white, - // extendBodyBehindAppBar: false, - // appBar: PreferredSize( - // preferredSize: Size.fromHeight( - // MediaQuery.of(context).size.height * 0.070), - // child: Container( - // height: MediaQuery.of(context).size.height * 0.070, - // decoration: BoxDecoration( - // border: Border( - // bottom: BorderSide( - // color: Theme.of(context).dividerColor, - // width: 0.5), //width: 0.7 - // ), - // color: Colors.white), - // child: Center( - // child: TabBar( - // isScrollable: false, - // controller: _tabController, - // // indicatorColor: Colors.transparent, - // indicatorWeight: 1.0, - // indicatorSize: TabBarIndicatorSize.tab, - // indicatorColor:Colors.green, - // labelColor: Theme.of(context).primaryColor, - // labelPadding: EdgeInsets.only( - // top: 0, left: 0, right: 0, bottom: 0), - // unselectedLabelColor: Colors.grey[800], - // tabs: [ - // tabWidget(screenSize, _activeTab == 0, - // TranslationBase.of(context).details, - // ), - // tabWidget(screenSize, _activeTab == 1, - // TranslationBase.of(context).review, - // ), - // tabWidget(screenSize, _activeTab == 2, - // TranslationBase.of(context).availability), - // ], - // ), - // ), - // ), - // ), - // body: Column( - // children: [ - // Expanded( - // child: TabBarView( - // physics: BouncingScrollPhysics(), - // controller: _tabController, - // children: [ - // DetailsInfo( - // product: widget.product, - // ), - // ReviewsInfo( - // product: widget.product, - // ), - // AvailabilityInfo() - // ], - // ), - // ), - // - // ], - // ), - // ), - // ), - - SizedBox( - height: 6, - ), - - //TODO Elham* Remove this - 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), + 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, ), - color: Colors.white, - ), - CustomDivider( - color: isDetails - ? Colors.green - : Colors.transparent, - ) - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () { - setState(() { - isDetails = false; - isReviews = true; - isAvailability = false; - }); - }, - child: Text( - TranslationBase.of(context).reviews, - style: TextStyle( - fontSize: 16, - 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); + } + setState(() { + isDetails = false; + isReviews = true; + isAvailability = false; + }); + }, + child: Text( + TranslationBase.of(context).reviews, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + color: Colors.white, ), - color: Colors.white, - ), - CustomDivider( - color: isReviews - ? Colors.green - : Colors.transparent, - ), - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () { - setState(() { - isDetails = false; - isReviews = false; - isAvailability = true; - }); - }, - child: Text( - TranslationBase.of(context).availability, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold), + CustomDivider( + color: isReviews + ? 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, - ) - : isAvailability - ? AvailabilityInfo() - : Container(), - ], - ), - ), - - ///TODO Elham* check if we need recommanded - // Row( - // children: [ - // customerId != null - // ? Container( - // width: 410, - // height: 50, - // color: Colors.white, - // child: Texts( - // TranslationBase.of(context).recommended, - // bold: true, - // ), - // ) - // : Container(), - // ], - // ), - // RecommendedProducts(product: widget.product) + ], + ), + SizedBox( + width: 20, + ), + Column( + children: [ + FlatButton( + onPressed: () async { + GifLoaderDialogUtils.showMyDialog( + context); + await model.getProductLocationData(); + GifLoaderDialogUtils.hideDialog(context); - SizedBox( - height: 80, - ) - ], + 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, + ), + ], + ), + ], + ), + SizedBox( + height: 10, + ), + isDetails + ? DetailsInfo( + product: widget.product, + ) + : isReviews + ? ReviewsInfo( + product: widget.product, + previousModel: model, + ) + : isAvailability + ? AvailabilityInfo( + previousModel: model, + ) + : Container(), + ], + ), + ), + SizedBox( + height: 80, + ) + ], + ), ), - ), - bottomSheet: FooterWidget( - widget.product.stockAvailability != 'Out of stock', - widget.product.orderMaximumQuantity, - widget.product.orderMinimumQuantity, - widget.product.stockQuantity, - widget.product, - price: price, - isOverQuantity: isOverQuantity, - addToCartFunction: addToCartFunction, - ), - ); - + bottomSheet: FooterWidget( + widget.product.stockAvailability != 'Out of stock', + widget.product.orderMaximumQuantity, + widget.product.orderMinimumQuantity, + widget.product.stockQuantity, + widget.product, + price: price, + isOverQuantity: isOverQuantity, + addToCartFunction: addToCartFunction, + ), + )); } } 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 619a4fb1..4301ce36 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 @@ -10,7 +10,7 @@ import 'package:provider/provider.dart'; import 'package:rating_bar/rating_bar.dart'; import '../../../../locator.dart'; -import 'CustomIcon.dart'; +import 'shared/icon_with_bg.dart'; class ProductNameAndPrice extends StatefulWidget { BuildContext context; diff --git a/lib/pages/pharmacies/screens/product-details/reviews_info.dart b/lib/pages/pharmacies/screens/product-details/reviews_info.dart index c48e249f..15260071 100644 --- a/lib/pages/pharmacies/screens/product-details/reviews_info.dart +++ b/lib/pages/pharmacies/screens/product-details/reviews_info.dart @@ -1,97 +1,89 @@ 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'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; -import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:flutter/material.dart'; import 'package:rating_bar/rating_bar.dart'; class ReviewsInfo extends StatelessWidget { final PharmacyProduct product; + final ProductDetailViewModel previousModel; - const ReviewsInfo({Key key, this.product}) : super(key: key); + const ReviewsInfo({Key key, this.product, this.previousModel}) : super(key: key); @override Widget build(BuildContext context) { - return BaseView( - onModelReady: (model) => model.getProductReviewsData(product.id), - allowAny: true, - builder: (_, model, wi) => NetworkBaseView( - baseViewModel:model , - child: model.productDetailService.length != 0 && - model.productDetailService[0].reviews.length != 0 - ? ListView.builder( - physics: ScrollPhysics(), - itemCount: model.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( - children: [ - Container( - child: Text( - model.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: model.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( - child: Text( - model.productDetailService[0].reviews[index] - .reviewText, - style: TextStyle(fontSize: 20), - ), - ), - SizedBox( - height: 50, - ), - Divider(height: 1, color: Colors.grey), - ], + return previousModel.productDetailService.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( + children: [ + Container( + child: Text( + previousModel.productDetailService[0].reviews[index] + .customerId + .toString(), + style: TextStyle( + fontSize: 17, + color: Colors.grey, + fontWeight: FontWeight.w600), + ), ), - ); - }, - ) - : Container( - padding: EdgeInsets.all(15), - alignment: Alignment.center, + 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( child: Text( - TranslationBase.of(context).noReviewsAvailable, + previousModel.productDetailService[0].reviews[index] + .reviewText, + style: TextStyle(fontSize: 20), ), -// Text('No Reviews Available'), ), + SizedBox( + height: 50, + ), + Divider(height: 1, color: Colors.grey), + ], + ), + ); + }, + ) + : Container( + 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/CustomIcon.dart b/lib/pages/pharmacies/screens/product-details/shared/icon_with_bg.dart similarity index 93% rename from lib/pages/pharmacies/screens/product-details/CustomIcon.dart rename to lib/pages/pharmacies/screens/product-details/shared/icon_with_bg.dart index fc8b2288..9033cd72 100644 --- a/lib/pages/pharmacies/screens/product-details/CustomIcon.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/icon_with_bg.dart @@ -11,7 +11,6 @@ class IconWithBg extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - // margin: EdgeInsets.only(left: 25), width: 40, height: 40, decoration: BoxDecoration( diff --git a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart similarity index 96% rename from lib/pages/pharmacies/screens/product-details/ProductAppBar.dart rename to lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart index 2fad8016..0fd1f03d 100644 --- a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart +++ b/lib/pages/pharmacies/screens/product-details/shared/product_details_app_bar.dart @@ -7,10 +7,10 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; -import '../../../../locator.dart'; -import '../../compare-list.dart'; -import '../cart-order-page.dart'; -import 'CustomIcon.dart'; +import '../../../../../locator.dart'; +import '../../../compare-list.dart'; +import '../../cart-order-page.dart'; +import 'icon_with_bg.dart'; class ProductAppBar extends StatelessWidget with PreferredSizeWidget { From 3b79d0ac41deec5261b01a5d15c15953c184c560 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 11:45:11 +0300 Subject: [PATCH 06/15] return the disable colors --- .../screens/product-details/footor/footer-widget.dart | 10 ++++++---- .../screens/product-details/product-detail.dart | 5 ++--- lib/widgets/buttons/secondary_button.dart | 5 +++-- 3 files changed, 11 insertions(+), 9 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 7cdfe7f2..4233e42a 100644 --- a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart +++ b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart @@ -189,13 +189,14 @@ class _FooterWidgetState extends State { disabled: !widget.isAvailable && widget.price > 0 || widget.price > widget.quantityLimit || widget.item.rxMessage != null, - onTap: () { + disableColor: Colors.green[400], + onTap: () async { if (!authenticatedUserObject.isLogin) { Navigator.of(context).pushNamed( WELCOME_LOGIN, ); } else - widget.addToCartFunction( + await widget.addToCartFunction( widget.price, widget.item.id, context); }, borderRadius: 5, @@ -212,8 +213,8 @@ class _FooterWidgetState extends State { disabled: !widget.isAvailable && widget.price > 0 || widget.price > widget.quantityLimit || widget.item.rxMessage != null, - onTap: () { - widget.addToCartFunction( + onTap: () async { + await widget.addToCartFunction( widget.price, widget.item.id, context); Navigator.push( context, @@ -221,6 +222,7 @@ class _FooterWidgetState extends State { ); }, borderRadius: 5, + disableColor: Colors.grey[700], color: !widget.isAvailable && widget.price > 0 || widget.price > widget.quantityLimit || widget.item.rxMessage != null diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index c263f77a..63765ed4 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -357,9 +357,8 @@ convertCityName(txt) { addToCartFunction(quantity, itemID, BuildContext context) async { GifLoaderDialogUtils.showMyDialog(context); ProductDetailViewModel x = new ProductDetailViewModel(); - await x.addToCartData(quantity, itemID).then((value) { - GifLoaderDialogUtils.hideDialog(context); - }); + await x.addToCartData(quantity, itemID); + GifLoaderDialogUtils.hideDialog(context); } notifyMeWhenAvailable(context, itemId) async { diff --git a/lib/widgets/buttons/secondary_button.dart b/lib/widgets/buttons/secondary_button.dart index 9d5df436..4b2f23a9 100644 --- a/lib/widgets/buttons/secondary_button.dart +++ b/lib/widgets/buttons/secondary_button.dart @@ -29,7 +29,7 @@ class SecondaryButton extends StatefulWidget { this.small = false, this.disabled = false, this.borderColor, - this.noBorderRadius = false, this.borderRadius}) + this.noBorderRadius = false, this.borderRadius, this.disableColor}) : super(key: key); final String label; @@ -44,6 +44,7 @@ class SecondaryButton extends StatefulWidget { final bool disabled; final bool noBorderRadius; final double borderRadius; + final Color disableColor; @@ -183,7 +184,7 @@ class _SecondaryButtonState extends State height: 100, decoration: BoxDecoration( color: widget.disabled - ? Colors.grey + ? widget.disableColor??Colors.grey : widget.color ?? Theme.of(context).buttonColor), ), ), From 055b888ba239a61d74569b3cb7fe2b5357a4ce8a Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 12:09:44 +0300 Subject: [PATCH 07/15] fix address --- .../AmbulanceRequestIndexPages/PickupLocation.dart | 8 ++++++-- .../pharmacy/pharmacyAddresses/AddAddress.dart | 13 +++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart b/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart index ce4eb2f7..e05f0e95 100644 --- a/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart +++ b/lib/pages/ErService/AmbulanceRequestIndexPages/PickupLocation.dart @@ -51,6 +51,9 @@ class _PickupLocationState extends State { void initState() { super.initState(); _getCurrentLocation(); + setState(() { + + }); } _getCurrentLocation() async { @@ -61,6 +64,7 @@ class _PickupLocationState extends State { _longitude = 0; _latitude = 0; }); + } @override @@ -89,8 +93,8 @@ class _PickupLocationState extends State { context, FadePage( page: PickupLocationFromMap( - latitude: _latitude, - longitude: _longitude, + latitude: _latitude??0, + longitude: _longitude??0, onPick: (value) { setState(() { _result = value; diff --git a/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart b/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart index 7569ed43..1665cb78 100644 --- a/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart +++ b/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart @@ -35,8 +35,14 @@ class _AddAddressPageState extends State { } else { _getCurrentLocation(); } + + setState(() { + }); } + + + _getCurrentLocation() async { await Geolocator.getLastKnownPosition().then((value) { _latitude = value.latitude; @@ -44,9 +50,12 @@ class _AddAddressPageState extends State { }).catchError((e) { _longitude = 0; _latitude = 0; + + }); } + @override Widget build(BuildContext context) { final mediaQuery = MediaQuery.of(context); @@ -63,8 +72,8 @@ class _AddAddressPageState extends State { body: Container( height: height * 1, child: PickupLocationFromMap( - latitude: _latitude, - longitude: _longitude, + latitude: _latitude??0, + longitude: _longitude??0, isWithAppBar: false, buttonColor: Color(0xFF5AB145), buttonLabel: TranslationBase.of(context).save, From 0d2d4c64c2e1faefadb6561448a02f49468e2b1c Mon Sep 17 00:00:00 2001 From: mosazaid Date: Wed, 6 Oct 2021 12:45:05 +0300 Subject: [PATCH 08/15] fix bugs pharmacy home and increase performance --- .../parmacyModule/parmacy_module_service.dart | 8 +- lib/pages/landing/landing_page_pharmcy.dart | 7 ++ .../pharmacies/widgets/ProductTileItem.dart | 81 ++++++++++--------- .../widgets/home/BestSellerWidget.dart | 4 +- .../pharmacies/widgets/home/GridViewCard.dart | 1 + .../widgets/home/RecentlyViewedWidget.dart | 4 +- .../widgets/home/ShopByBrandWidget.dart | 2 +- .../pharmacies/widgets/manufacturerItem.dart | 4 +- 8 files changed, 66 insertions(+), 45 deletions(-) diff --git a/lib/core/service/parmacyModule/parmacy_module_service.dart b/lib/core/service/parmacyModule/parmacy_module_service.dart index b32b86e0..5a0a9e54 100644 --- a/lib/core/service/parmacyModule/parmacy_module_service.dart +++ b/lib/core/service/parmacyModule/parmacy_module_service.dart @@ -113,6 +113,7 @@ class PharmacyModuleService extends BaseService { } Future getTopManufacturerList() async { + if (manufacturerList.isNotEmpty) return; Map queryParams = {'page': '1', 'limit': '8'}; try { await baseAppClient.getPharmacy(GET_PHARMACY_TOP_MANUFACTURER, @@ -121,7 +122,7 @@ class PharmacyModuleService extends BaseService { response['manufacturer'].forEach((item) { Manufacturer manufacturer = Manufacturer.fromJson(item); // if (manufacturer.image != null) { - manufacturerList.add(Manufacturer.fromJson(item)); + manufacturerList.add(Manufacturer.fromJson(item)); // } }); hasError = false; @@ -135,6 +136,8 @@ class PharmacyModuleService extends BaseService { } Future getBestSellerProducts() async { + if (bestSellerProducts.isNotEmpty) return; + Map queryParams = { 'fields': 'id,discount_ids,name,namen,localized_names,display_order,short_description,full_description,full_descriptionn,sku,order_minimum_quantity,order_maximum_quantity,price,old_price,images,is_rx,rx_message,rx_messagen,discount_name,discount_namen,approved_rating_sum,approved_total_reviews,allow_back_in_stock_subscriptions,stock_quantity,stock_availability,stock_availabilityn,discount_percentage,reviews', @@ -173,7 +176,8 @@ class PharmacyModuleService extends BaseService { }); hasError = false; }, onFailure: (String error, int statusCode) { - hasError = true; // sharedPref.setString(PHARMACY_LAST_VISITED_PRODUCTS, ""); + hasError = + true; // sharedPref.setString(PHARMACY_LAST_VISITED_PRODUCTS, ""); super.error = error; }); } catch (error) { diff --git a/lib/pages/landing/landing_page_pharmcy.dart b/lib/pages/landing/landing_page_pharmcy.dart index 9f00e27c..4927c163 100644 --- a/lib/pages/landing/landing_page_pharmcy.dart +++ b/lib/pages/landing/landing_page_pharmcy.dart @@ -2,6 +2,7 @@ import 'package:barcode_scan_fix/barcode_scan.dart'; import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart'; +import 'package:diplomaticquarterapp/core/service/parmacyModule/parmacy_module_service.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-order-page.dart'; @@ -18,6 +19,8 @@ import 'package:diplomaticquarterapp/widgets/pharmacy/bottom_nav_pharmacy_bar.da import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; +import '../../locator.dart'; + class LandingPagePharmacy extends StatefulWidget { @override _LandingPagePharmacyState createState() => _LandingPagePharmacyState(); @@ -37,6 +40,10 @@ class _LandingPagePharmacyState extends State { void initState() { super.initState(); + locator().manufacturerList = []; + locator().bestSellerProducts = []; + locator().lastVisitedProducts = []; + pageController = PageController(keepPage: true); } diff --git a/lib/pages/pharmacies/widgets/ProductTileItem.dart b/lib/pages/pharmacies/widgets/ProductTileItem.dart index 07abe2db..a2400e63 100644 --- a/lib/pages/pharmacies/widgets/ProductTileItem.dart +++ b/lib/pages/pharmacies/widgets/ProductTileItem.dart @@ -13,8 +13,9 @@ import 'package:provider/provider.dart'; class ProductTileItem extends StatelessWidget { final AppSharedPreferences sharedPref = AppSharedPreferences(); final PharmacyProduct item; + final double itemHeight; - ProductTileItem(this.item); + ProductTileItem(this.item, this.itemHeight); void productOnClick(BuildContext ctx) { _saveLastVisitProducts(); @@ -92,12 +93,12 @@ class ProductTileItem extends StatelessWidget { ? Image.network( item.images[0].src, fit: BoxFit.cover, - height: 80, + height: itemHeight / 2, ) : Image.asset( "assets/images/no_image.png", fit: BoxFit.cover, - height: 80, + height: itemHeight / 2, ), ), Container( @@ -125,42 +126,48 @@ class ProductTileItem extends StatelessWidget { ], ), SizedBox(height: 8,), - Container( - margin: EdgeInsets.symmetric( - horizontal: 6, - vertical: 0, + Padding( + padding: const EdgeInsets.symmetric(horizontal: 6.0), + child: Texts( + projectProvider.isArabic ? item.namen : item.name, + regular: true, + fontSize: 12, + fontWeight: FontWeight.w400, ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Texts( - projectProvider.isArabic ? item.namen : item.name, - regular: true, - fontSize: 12, - fontWeight: FontWeight.w400, - ), - Padding( - padding: const EdgeInsets.only(top: 4, bottom: 4), - child: Texts( - "SAR ${item.price}", - fontWeight: FontWeight.w600, - fontSize: 14, - ), - ), - Row( - children: [ - Expanded( - child: StarRating( - totalAverage: item.approvedTotalReviews > 0 - ? (item.approvedRatingSum.toDouble() / - item.approvedTotalReviews.toDouble()) - .toDouble() - : 0, - forceStars: true), + ), + Expanded( + child: Container( + margin: EdgeInsets.symmetric( + horizontal: 6, + vertical: 0, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.only(top: 4, bottom: 4), + child: Texts( + "SAR ${item.price}", + fontWeight: FontWeight.w600, + fontSize: 14, ), - ], - ), - ], + ), + Row( + children: [ + Expanded( + child: StarRating( + totalAverage: item.approvedTotalReviews > 0 + ? (item.approvedRatingSum.toDouble() / + item.approvedTotalReviews.toDouble()) + .toDouble() + : 0, + forceStars: true), + ), + ], + ), + ], + ), ), ), SizedBox(height: 5,), diff --git a/lib/pages/pharmacies/widgets/home/BestSellerWidget.dart b/lib/pages/pharmacies/widgets/home/BestSellerWidget.dart index baf771b2..2814bc1c 100644 --- a/lib/pages/pharmacies/widgets/home/BestSellerWidget.dart +++ b/lib/pages/pharmacies/widgets/home/BestSellerWidget.dart @@ -29,10 +29,10 @@ class BestSellerWidget extends StatelessWidget { )), if (model.state != ViewState.BusyLocal) Container( - height: MediaQuery.of(context).size.height / 4 + 20, + height: MediaQuery.of(context).size.height / 3 + 20, child: ListView.builder( itemBuilder: (ctx, i) => - ProductTileItem(model.bestSellerProduct[i]), + ProductTileItem(model.bestSellerProduct[i], MediaQuery.of(context).size.height / 4 + 20), scrollDirection: Axis.horizontal, itemCount: model.bestSellerProduct.length, ), diff --git a/lib/pages/pharmacies/widgets/home/GridViewCard.dart b/lib/pages/pharmacies/widgets/home/GridViewCard.dart index a8e3fe9b..fd8bdada 100644 --- a/lib/pages/pharmacies/widgets/home/GridViewCard.dart +++ b/lib/pages/pharmacies/widgets/home/GridViewCard.dart @@ -47,6 +47,7 @@ class GridViewCard extends StatelessWidget { TranslationBase.of(context).viewAll, handler: handler, tPadding: 0, + textColor: Color(0xFF5ab145), bPadding: 0, ), Expanded(child: Container()), diff --git a/lib/pages/pharmacies/widgets/home/RecentlyViewedWidget.dart b/lib/pages/pharmacies/widgets/home/RecentlyViewedWidget.dart index 15e9e700..3e7cf5fe 100644 --- a/lib/pages/pharmacies/widgets/home/RecentlyViewedWidget.dart +++ b/lib/pages/pharmacies/widgets/home/RecentlyViewedWidget.dart @@ -30,11 +30,11 @@ class RecentlyViewedWidget extends StatelessWidget { if (model.state != ViewState.BusyLocal) Container( height: model.lastVisitedProducts.length > 0 - ? MediaQuery.of(context).size.height / 4 + 20 + ? MediaQuery.of(context).size.height / 3 + 20 : 0, child: ListView.builder( itemBuilder: (ctx, i) => - ProductTileItem(model.lastVisitedProducts[i]), + ProductTileItem(model.lastVisitedProducts[i], MediaQuery.of(context).size.height / 4 + 20), scrollDirection: Axis.horizontal, itemCount: model.lastVisitedProducts.length, ), diff --git a/lib/pages/pharmacies/widgets/home/ShopByBrandWidget.dart b/lib/pages/pharmacies/widgets/home/ShopByBrandWidget.dart index 8f4f943d..7fcdbfe8 100644 --- a/lib/pages/pharmacies/widgets/home/ShopByBrandWidget.dart +++ b/lib/pages/pharmacies/widgets/home/ShopByBrandWidget.dart @@ -25,7 +25,7 @@ class ShopByBrandWidget extends StatelessWidget { ProductBrandsPage()), if (model.state != ViewState.BusyLocal) Container( - height: 100, + height: 150, child: ListView.builder( itemBuilder: (ctx, i) => ManufacturerItem(model.manufacturerList[i]), diff --git a/lib/pages/pharmacies/widgets/manufacturerItem.dart b/lib/pages/pharmacies/widgets/manufacturerItem.dart index df5fb166..c5b6bf23 100644 --- a/lib/pages/pharmacies/widgets/manufacturerItem.dart +++ b/lib/pages/pharmacies/widgets/manufacturerItem.dart @@ -25,6 +25,7 @@ class ManufacturerItem extends StatelessWidget { ); }, child: Container( + width: 100, margin: EdgeInsets.symmetric( horizontal: 12, vertical: 4, @@ -38,8 +39,9 @@ class ManufacturerItem extends StatelessWidget { top: BorderSide(color: Colors.grey.shade300, width: 1)), ), child: item.image == null - ? Padding( + ? Container( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 10), + alignment: Alignment.topCenter, child: AppText(item.name, fontWeight: FontWeight.w500,fontSize: 14,), ) : Padding( From 2981eb3236252afc47902472b67fe8ee9e6a372a Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 15:53:52 +0300 Subject: [PATCH 09/15] fix public card issues --- lib/pages/final_products_page.dart | 1 - lib/pages/pharmacies/my_reviews.dart | 2 +- .../product-details/availability_info.dart | 9 + .../product-details/footor/footer-widget.dart | 37 +- .../product-details/product-detail.dart | 134 ++---- .../product-details/recommended_products.dart | 442 ++++++++---------- .../shared/custom-divider.dart | 19 + .../shared/product_details_app_bar.dart | 100 ++-- .../others/app_scafold_detail_page.dart | 281 ----------- 9 files changed, 341 insertions(+), 684 deletions(-) create mode 100644 lib/pages/pharmacies/screens/product-details/shared/custom-divider.dart delete mode 100644 lib/widgets/others/app_scafold_detail_page.dart diff --git a/lib/pages/final_products_page.dart b/lib/pages/final_products_page.dart index 31747141..fff272b3 100644 --- a/lib/pages/final_products_page.dart +++ b/lib/pages/final_products_page.dart @@ -49,7 +49,6 @@ class _FinalProductsPageState extends State { Widget build(BuildContext context) { return BaseView( onModelReady: (model) { - //TODO Elham* fix all services in order handel errors in better way in the service if (widget.productType == 1) { model.getFinalProducts(i: id); appBarTitle = TranslationBase.of(context).products; diff --git a/lib/pages/pharmacies/my_reviews.dart b/lib/pages/pharmacies/my_reviews.dart index 7e7e33a0..47aa382f 100644 --- a/lib/pages/pharmacies/my_reviews.dart +++ b/lib/pages/pharmacies/my_reviews.dart @@ -137,7 +137,7 @@ reviewDetails(data, rate, myRate) { : Alignment.topLeft, child: RichText( text: TextSpan( - text: data.product.price.toString() + + text: data.product.quantity.toString() + " " + data.product.currency, style: TextStyle( diff --git a/lib/pages/pharmacies/screens/product-details/availability_info.dart b/lib/pages/pharmacies/screens/product-details/availability_info.dart index 6a6fdfd5..9e717de6 100644 --- a/lib/pages/pharmacies/screens/product-details/availability_info.dart +++ b/lib/pages/pharmacies/screens/product-details/availability_info.dart @@ -78,4 +78,13 @@ class AvailabilityInfo extends StatelessWidget { }, ); } + + convertCityName(txt) { + String stringTxt; + String newTxt; + stringTxt = txt.toString(); + newTxt = stringTxt.split('.')[1]; + + return newTxt; + } } 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 4233e42a..43abcae5 100644 --- a/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart +++ b/lib/pages/pharmacies/screens/product-details/footor/footer-widget.dart @@ -19,12 +19,12 @@ class FooterWidget extends StatefulWidget { final PharmacyProduct item; final Function addToCartFunction; - int price; + int quantity; bool isOverQuantity; FooterWidget(this.isAvailable, this.maxQuantity, this.minQuantity, this.quantityLimit, this.item, - {this.price, this.isOverQuantity = false, this.addToCartFunction}); + {this.quantity, this.isOverQuantity = false, this.addToCartFunction}); @override _FooterWidgetState createState() => _FooterWidgetState(); @@ -97,7 +97,7 @@ class _FooterWidgetState extends State { QuantityBox( label: i, onTapFunc: onChangeValue, - isSelected: widget.price == i), + isSelected: widget.quantity == i), Column( children: [ Container( @@ -111,14 +111,14 @@ class _FooterWidgetState extends State { decoration: InputDecoration( labelText: 'quantity #'), onChanged: (text) { - print(widget.price); + print(widget.quantity); print(widget.quantityLimit); if (int.tryParse(text) == null) { text = ''; } else { setState(() { - widget.price = int.parse(text); - if (widget.price >= + widget.quantity = int.parse(text); + if (widget.quantity >= widget.quantityLimit) { widget.isOverQuantity = true; } else { @@ -156,7 +156,7 @@ class _FooterWidgetState extends State { Expanded( flex: 4, child: Text( - widget.price.toString(), + widget.quantity.toString(), style: TextStyle(fontSize: 20), ), ), @@ -186,8 +186,8 @@ class _FooterWidgetState extends State { width: MediaQuery.of(context).size.width * 0.45, child: SecondaryButton( label: TranslationBase.of(context).addToCart.toUpperCase(), - disabled: !widget.isAvailable && widget.price > 0 || - widget.price > widget.quantityLimit || + disabled: !widget.isAvailable && widget.quantity > 0 || + widget.quantity > widget.quantityLimit || widget.item.rxMessage != null, disableColor: Colors.green[400], onTap: () async { @@ -197,7 +197,7 @@ class _FooterWidgetState extends State { ); } else await widget.addToCartFunction( - widget.price, widget.item.id, context); + widget.quantity, widget.item.id, context); }, borderRadius: 5, color: Colors.green, @@ -210,12 +210,12 @@ class _FooterWidgetState extends State { width: MediaQuery.of(context).size.width * 0.35, child: SecondaryButton( label: TranslationBase.of(context).buyNow.toUpperCase(), - disabled: !widget.isAvailable && widget.price > 0 || - widget.price > widget.quantityLimit || + disabled: !widget.isAvailable && widget.quantity > 0 || + widget.quantity > widget.quantityLimit || widget.item.rxMessage != null, onTap: () async { await widget.addToCartFunction( - widget.price, widget.item.id, context); + widget.quantity, widget.item.id, context); Navigator.push( context, FadePage(page: CartOrderPage()), @@ -223,8 +223,8 @@ class _FooterWidgetState extends State { }, borderRadius: 5, disableColor: Colors.grey[700], - color: !widget.isAvailable && widget.price > 0 || - widget.price > widget.quantityLimit || + color: !widget.isAvailable && widget.quantity > 0 || + widget.quantity > widget.quantityLimit || widget.item.rxMessage != null ? Colors.grey : Colors.grey[800], @@ -239,13 +239,12 @@ class _FooterWidgetState extends State { onChangeValue(int i) { setState(() { - ///TODO Elham* Check this if its good - widget.price = i; - if (widget.price >= widget.quantityLimit) { + widget.quantity = i; + if (widget.quantity >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; - return widget.price; + return widget.quantity; } }); } diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 63765ed4..f3524b35 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -1,43 +1,28 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.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/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/compare-list.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-name-and-price.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/recommended_products.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/reviews_info.dart'; -import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/shared/custom-divider.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; 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/others/app_scafold_detail_page.dart'; -import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart'; -import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:provider/provider.dart'; -import 'package:rating_bar/rating_bar.dart'; -import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.dart'; -import '../cart-order-page.dart'; -import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; -import 'shared/product_details_app_bar.dart'; import 'availability_info.dart'; import 'details_info.dart'; import 'discount_description.dart'; import 'footor/footer-widget.dart'; +import 'shared/product_details_app_bar.dart'; + + -int price = 0; -bool isOverQuantity = false; -bool isInWishList = false; -bool isSelected = true; String itemID; -var customerId; -CompareList compareItems = new CompareList(); PharmacyProduct specificationData; class ProductDetailPage extends StatefulWidget { @@ -49,23 +34,27 @@ class ProductDetailPage extends StatefulWidget { __ProductDetailPageState createState() => __ProductDetailPageState(); } -class __ProductDetailPageState extends State - with SingleTickerProviderStateMixin { - TabController _tabController; +class __ProductDetailPageState extends State{ AppSharedPreferences sharedPref = AppSharedPreferences(); bool isTrue = true; bool isDetails = true; bool isReviews = false; bool isAvailability = false; + String customerId; + bool isSelected = true; + bool isOverQuantity = false; + bool isInWishList = false; + int quantity = 0; + checkWishlist() async { GifLoaderDialogUtils.showMyDialog(context); - ProductDetailViewModel x = new ProductDetailViewModel(); - await x.checkWishlistData(); + ProductDetailViewModel model = new ProductDetailViewModel(); + await model.checkWishlistData(); - for (int i = 0; i < x.wishListItems.length; i++) { - if (itemID == x.wishListItems[i].product.id) { + for (int i = 0; i < model.wishListItems.length; i++) { + if (itemID == model.wishListItems[i].product.id) { isInWishList = true; break; } else { @@ -77,9 +66,8 @@ class __ProductDetailPageState extends State } void initState() { - price = 1; + quantity = 1; specificationData = widget.product; - _tabController = TabController(length: 3, vsync: this); userInfo(); super.initState(); @@ -87,7 +75,6 @@ class __ProductDetailPageState extends State @override void dispose() { - _tabController.dispose(); super.dispose(); } @@ -111,6 +98,11 @@ class __ProductDetailPageState extends State isShowDecPage: false, customAppBar: ProductAppBar( product: widget.product, + model: model, + addToWishlistFunction: (item) { + addToWishlistFunction(itemID:item,model:model); + setState(() {}); + }, ), body: SingleChildScrollView( child: Column( @@ -143,15 +135,15 @@ class __ProductDetailPageState extends State widget.product, customerId: customerId, addToWishlistFunction: (item) { - addToWishlistFunction(item); + addToWishlistFunction(itemID:item,model:model); setState(() {}); }, deleteFromWishlistFunction: (item) { - deleteFromWishlistFunction(item); + deleteFromWishlistFunction(itemID: item, model: model); setState(() {}); }, notifyMeWhenAvailable: (context, itemId) { - notifyMeWhenAvailable(context, itemId); + notifyMeWhenAvailable(itemId:itemId, customerId: customerId, model: model); }, isInWishList: isInWishList, ), @@ -319,85 +311,33 @@ class __ProductDetailPageState extends State widget.product.orderMinimumQuantity, widget.product.stockQuantity, widget.product, - price: price, + quantity: quantity, isOverQuantity: isOverQuantity, addToCartFunction: addToCartFunction, ), )); } -} - -class CustomDivider extends StatelessWidget { - const CustomDivider({ - Key key, - this.color, - }) : super(key: key); - final Color color; + addToWishlistFunction({itemID, ProductDetailViewModel model}) async { + isInWishList = true; + await model.addToWishlistData(itemID); + } - @override - Widget build(BuildContext context) { - return Container( - width: 120, - height: 2, - color: color, - ); + deleteFromWishlistFunction({itemID, ProductDetailViewModel model}) async { + isInWishList = false; + await model.deletWishlistData(itemID); } } -convertCityName(txt) { - String stringTxt; - String newTxt; - stringTxt = txt.toString(); - newTxt = stringTxt.split('.')[1]; - - return newTxt; -} -addToCartFunction(quantity, itemID, BuildContext context) async { +addToCartFunction({quantity, itemID, BuildContext context,ProductDetailViewModel model}) async { GifLoaderDialogUtils.showMyDialog(context); - ProductDetailViewModel x = new ProductDetailViewModel(); - await x.addToCartData(quantity, itemID); + await model.addToCartData(quantity, itemID); GifLoaderDialogUtils.hideDialog(context); } -notifyMeWhenAvailable(context, itemId) async { - ProductDetailViewModel x = new ProductDetailViewModel(); - await x.notifyMe(customerId, itemId); +notifyMeWhenAvailable({itemId, customerId,ProductDetailViewModel model }) async { + await model.notifyMe(customerId, itemId); } -addToWishlistFunction(itemID) async { - ProductDetailViewModel x = new ProductDetailViewModel(); - isInWishList = true; - await x.addToWishlistData(itemID); -} - -deleteFromWishlistFunction(itemID) async { - ProductDetailViewModel x = new ProductDetailViewModel(); - isInWishList = false; - await x.deletWishlistData(itemID); -} -//TODO Elham* move to file -Widget tabWidget( - Size screenSize, - bool isActive, - String title, -) { - return Center( - child: Container( - height: screenSize.height * 0.070, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - AppText( - title, - fontSize: SizeConfig.textMultiplier * 1.5, - // color: Color(0xFF2B353E), - fontWeight: FontWeight.w700, - ), - ], - ), - ), - ); -} diff --git a/lib/pages/pharmacies/screens/product-details/recommended_products.dart b/lib/pages/pharmacies/screens/product-details/recommended_products.dart index f40f1f08..7222ad85 100644 --- a/lib/pages/pharmacies/screens/product-details/recommended_products.dart +++ b/lib/pages/pharmacies/screens/product-details/recommended_products.dart @@ -1,6 +1,7 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.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/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; @@ -14,8 +15,23 @@ import 'package:rating_bar/rating_bar.dart'; class RecommendedProducts extends StatefulWidget { final PharmacyProduct product; + final String customerId; + final ProductDetailViewModel productDetailViewModel; + final bool isOverQuantity; + final bool isInWishList; + final Function addToWishlistFunction; + final Function deleteFromWishlistFunction; - const RecommendedProducts({Key key, this.product}) : super(key: key); + RecommendedProducts( + {Key key, + this.product, + this.productDetailViewModel, + this.customerId, + this.isOverQuantity = false, + this.isInWishList = false, + this.addToWishlistFunction, + this.deleteFromWishlistFunction}) + : super(key: key); @override _RecommendedProductsState createState() => _RecommendedProductsState(); @@ -39,273 +55,235 @@ class _RecommendedProductsState extends State { padding: EdgeInsets.only(bottom: 5), // margin: EdgeInsets.symmetric(horizontal: 6, vertical: 4), child: BaseView( - onModelReady: (model) => model - .getRecommendedProducts(widget.product.id), + onModelReady: (model) => + model.getRecommendedProducts(widget.product.id), builder: (_, model, wi) => Container( - child: - model.recommendedProductList.length != null + child: model.recommendedProductList.length != null ? ListView.builder( - scrollDirection: - Axis.horizontal, + scrollDirection: Axis.horizontal, shrinkWrap: true, physics: ScrollPhysics(), // physics: NeverScrollableScrollPhysics(), - itemCount: model - .recommendedProductList - .length, + itemCount: model.recommendedProductList.length, itemBuilder: (context, index) { return InkWell( onTap: () async { - GifLoaderDialogUtils - .showMyDialog( - context); - RecommendedProductModel - data = - model.recommendedProductList[ - index]; + GifLoaderDialogUtils.showMyDialog(context); + RecommendedProductModel data = + model.recommendedProductList[index]; var json = data.toJson(); PharmacyProduct product = - new PharmacyProduct - .fromJson(json); - await Navigator - .pushReplacement( + new PharmacyProduct.fromJson(json); + await Navigator.pushReplacement( context, FadePage( - page: - ProductDetailPage( - product), + page: ProductDetailPage(product), ), ); - GifLoaderDialogUtils - .hideDialog(context); + GifLoaderDialogUtils.hideDialog(context); }, child: Card( elevation: 2, - shape: - RoundedRectangleBorder( + shape: RoundedRectangleBorder( side: BorderSide( - color: Colors - .grey[300], - width: 2), - borderRadius: - BorderRadius - .circular(10), + color: Colors.grey[300], width: 2), + borderRadius: BorderRadius.circular(10), ), - margin: - EdgeInsets.symmetric( + margin: EdgeInsets.symmetric( horizontal: 8, vertical: 0, ), child: Container( - decoration: - BoxDecoration( - borderRadius: - BorderRadius.all( + 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.start, children: [ Stack(children: [ Container( 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, - onPressed: - () async { - if (customerId != - null) { - if (!isInWishList && - model.recommendedProductList[index].isinwishlist != + 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, + onPressed: () async { + if (widget.customerId != null) { + if (!widget.isInWishList && + model + .recommendedProductList[ + index] + .isinwishlist != true) { - GifLoaderDialogUtils.showMyDialog( - context); - await addToWishlistFunction(model - .recommendedProductList[index] - .id); + GifLoaderDialogUtils + .showMyDialog(context); + await widget.addToWishlistFunction( + itemID: model + .recommendedProductList[ + index] + .id, + model: widget + .productDetailViewModel); // checkWishlist(); - GifLoaderDialogUtils.hideDialog( - context); - setState( - () { - model.recommendedProductList[index].isinwishlist = - true; - }); + GifLoaderDialogUtils + .hideDialog(context); + setState(() { + model + .recommendedProductList[ + index] + .isinwishlist = true; + }); } else { - GifLoaderDialogUtils.showMyDialog( - context); - await deleteFromWishlistFunction(model - .recommendedProductList[index] - .id); - GifLoaderDialogUtils.hideDialog( - context); - setState( - () { - model.recommendedProductList[index].isinwishlist = - false; - }); + GifLoaderDialogUtils + .showMyDialog(context); + await widget.deleteFromWishlistFunction( + itemID: model + .recommendedProductList[ + index] + .id, + model: widget + .productDetailViewModel); + GifLoaderDialogUtils + .hideDialog(context); + setState(() { + model + .recommendedProductList[ + index] + .isinwishlist = false; + }); } } else { return; } - setState( - () { - // checkWishlist(); - }); + setState(() { + // checkWishlist(); + }); }, ), ), ), Container( - margin: EdgeInsets - .fromLTRB( - 0, - 16, - 10, - 16), - alignment: - Alignment - .center, - child: (model.recommendedProductList[index].images != - null && - model.recommendedProductList[index].images.length > - 0) - ? Image - .network( - model - .recommendedProductList[index] - .images[0] - .src - .toString(), - fit: BoxFit - .cover, - height: - 60, - ) - : Image - .asset( - "assets/images/no_image.png", - fit: BoxFit - .cover, - height: - 60, - ), + margin: EdgeInsets.fromLTRB( + 0, 16, 10, 16), + alignment: Alignment.center, + child: (model + .recommendedProductList[ + index] + .images != + null && + model + .recommendedProductList[ + index] + .images + .length > + 0) + ? Image.network( + model + .recommendedProductList[ + index] + .images[0] + .src + .toString(), + fit: BoxFit.cover, + height: 60, + ) + : Image.asset( + "assets/images/no_image.png", + fit: BoxFit.cover, + height: 60, + ), ), Container( width: model - .recommendedProductList[ - index] - .rxMessage != - null + .recommendedProductList[ + index] + .rxMessage != + null ? MediaQuery.of(context) - .size - .width / - 5 + .size + .width / + 5 : 0, - padding: - EdgeInsets - .all(4), - decoration: - BoxDecoration( - color: Color( - 0xffb23838), - borderRadius: - BorderRadius - .only( - topLeft: Radius - .circular( - 6), + padding: EdgeInsets.all(4), + decoration: BoxDecoration( + color: Color(0xffb23838), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(6), ), ), - child: model.recommendedProductList[index] - .rxMessage != - null + child: model + .recommendedProductList[ + index] + .rxMessage != + null ? Texts( - projectViewModel.isArabic - ? model.recommendedProductList[index].rxMessagen - : model.recommendedProductList[index].rxMessage, - color: Colors - .white, - regular: - true, - fontSize: - 10, - fontWeight: - FontWeight.w400, - ) + projectViewModel.isArabic + ? model + .recommendedProductList[ + index] + .rxMessagen + : model + .recommendedProductList[ + index] + .rxMessage, + color: Colors.white, + regular: true, + fontSize: 10, + fontWeight: FontWeight.w400, + ) : Texts(""), ), ]), Container( - margin: EdgeInsets - .symmetric( + margin: EdgeInsets.symmetric( horizontal: 6, vertical: 0, ), child: Column( crossAxisAlignment: - CrossAxisAlignment - .start, + CrossAxisAlignment.start, children: [ Text( - projectViewModel - .isArabic + projectViewModel.isArabic ? model - .recommendedProductList[ - index] - .namen + .recommendedProductList[ + index] + .namen : model - .recommendedProductList[index] - .name, - style: - TextStyle( - color: Colors - .black, - fontSize: - 13.0, + .recommendedProductList[ + index] + .name, + style: TextStyle( + 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( + padding: const EdgeInsets.only( + top: 10, bottom: 5), + child: Texts( "SAR ${model.recommendedProductList[index].price}", - bold: - true, - fontSize: - 14, + bold: true, + fontSize: 14, ), ), ], @@ -313,47 +291,35 @@ class _RecommendedProductsState extends State { ), Row( crossAxisAlignment: - CrossAxisAlignment - .start, - children: < - Widget>[ + CrossAxisAlignment.start, + children: [ Container( - padding: EdgeInsets.only( - right: - 10), - child: - Align( - alignment: - Alignment - .topLeft, - child: RatingBar - .readOnly( + padding: + EdgeInsets.only(right: 10), + child: Align( + alignment: Alignment.topLeft, + child: RatingBar.readOnly( initialRating: model - .recommendedProductList[index] + .recommendedProductList[ + index] .approvedRatingSum .toDouble(), - size: - 13.0, + size: 13.0, filledColor: - Colors.yellow[700], - emptyColor: - Colors.grey[500], - isHalfAllowed: - true, + Colors.yellow[700], + emptyColor: Colors.grey[500], + isHalfAllowed: true, halfFilledIcon: - Icons.star_half, - filledIcon: - Icons.star, - emptyIcon: - Icons.star, + Icons.star_half, + filledIcon: Icons.star, + emptyIcon: Icons.star, ), ), ), Texts( "(${model.recommendedProductList[index].notApprovedTotalReviews.toString()})", // bold: true, - fontSize: - 12, + fontSize: 12, ), ]), ], @@ -363,20 +329,18 @@ class _RecommendedProductsState extends State { ); }) : Container( - // color: Colors.white, - child: Row( - mainAxisAlignment: - MainAxisAlignment.center, - // crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Texts( - TranslationBase.of(context) - .nonRecommended, - color: Colors.black, + // color: Colors.white, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + // crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Texts( + TranslationBase.of(context).nonRecommended, + color: Colors.black, + ), + ], + ), ), - ], - ), - ), ), ), ), diff --git a/lib/pages/pharmacies/screens/product-details/shared/custom-divider.dart b/lib/pages/pharmacies/screens/product-details/shared/custom-divider.dart new file mode 100644 index 00000000..268e79d0 --- /dev/null +++ b/lib/pages/pharmacies/screens/product-details/shared/custom-divider.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; + +class CustomDivider extends StatelessWidget { + const CustomDivider({ + Key key, + this.color, + }) : super(key: key); + + final Color color; + + @override + Widget build(BuildContext context) { + return Container( + width: 120, + height: 2, + color: color, + ); + } +} \ 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 0fd1f03d..95689326 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 @@ -1,5 +1,6 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.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'; @@ -13,19 +14,22 @@ import '../../cart-order-page.dart'; import 'icon_with_bg.dart'; class ProductAppBar extends StatelessWidget with PreferredSizeWidget { - final PharmacyProduct product; - ProductAppBar({Key key, this.product}) : super(key: key); + final ProductDetailViewModel model; + final Function addToWishlistFunction; + final int quantity; + + ProductAppBar({Key key, this.product, this.model, this.addToWishlistFunction, this.quantity}) + : super(key: key); AuthenticatedUserObject authenticatedUserObject = - locator(); + locator(); @override Widget build(BuildContext context) { return Container( color: Colors.white, - child: FractionallySizedBox( widthFactor: 0.95, child: Column( @@ -47,29 +51,31 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { ), ], ), - if(authenticatedUserObject.isLogin) - Row( - children: [ - IconWithBg( - icon: Icons.shopping_cart, + if (authenticatedUserObject.isLogin) + Row( + children: [ + IconWithBg( + icon: Icons.shopping_cart, + color: Colors.grey, + onPress: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => CartOrderPage()), + ); + }), + SizedBox( + width: 10, + ), + IconWithBg( + icon: FontAwesomeIcons.ellipsisV, color: Colors.grey, onPress: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => CartOrderPage()), - ); - }), - SizedBox(width: 10,), - IconWithBg( - icon: FontAwesomeIcons.ellipsisV, - color: Colors.grey, - onPress: () { - settingModalBottomSheet(context); - }, - ), - ], - ) + settingModalBottomSheet(context); + }, + ), + ], + ) ], ), ], @@ -78,10 +84,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { ); } - - @override - // TODO: implement preferredSize @override Size get preferredSize => Size(double.maxFinite, 50); @@ -92,27 +95,34 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { return Container( child: new Wrap( children: [ - if( product.stockAvailability != 'Out of stock') - new ListTile( - leading: Icon(Icons.shopping_cart), - title: Text( - TranslationBase.of(context).addToCart, - ), - onTap: () => { - if (price > 0) - {addToCartFunction(price, itemID, context)} - else - { - AppToast.showErrorToast( - message: "you should add quantity") - } - }), + if (product.stockAvailability != 'Out of stock') + new ListTile( + leading: Icon(Icons.shopping_cart), + 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") + } + }), ListTile( leading: Icon(Icons.favorite_border), title: Text( TranslationBase.of(context).addToWishlist, ), - onTap: () => {addToWishlistFunction(itemID)}, + onTap: () => + {addToWishlistFunction(itemID: itemID, model: model)}, ), ListTile( leading: Icon(Icons.compare), @@ -130,5 +140,3 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { }); } } - - diff --git a/lib/widgets/others/app_scafold_detail_page.dart b/lib/widgets/others/app_scafold_detail_page.dart deleted file mode 100644 index 595e0872..00000000 --- a/lib/widgets/others/app_scafold_detail_page.dart +++ /dev/null @@ -1,281 +0,0 @@ -import 'package:diplomaticquarterapp/config/config.dart'; -import 'package:diplomaticquarterapp/config/size_config.dart'; -import 'package:diplomaticquarterapp/config/size_config.dart'; -import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; -import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; -import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; -import 'package:diplomaticquarterapp/pages/insurance/insurance_update_screen.dart'; -import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/compare-list.dart'; -import 'package:diplomaticquarterapp/routes.dart'; -import 'package:diplomaticquarterapp/uitl/app_toast.dart'; -import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; -import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; -import 'package:diplomaticquarterapp/widgets/others/bottom_bar.dart'; -import 'package:diplomaticquarterapp/widgets/progress_indicator/app_loader_widget.dart'; -import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:provider/provider.dart'; - -import '../../locator.dart'; -import 'floating_button_search.dart'; -import '../progress_indicator/app_loader_widget.dart'; -import 'arrow_back.dart'; -import 'network_base_view.dart'; -import 'not_auh_page.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-order-page.dart'; - -class DetailPageScafold extends StatefulWidget { - final String appBarTitle; - final Widget body; - final Widget bottomSheet; - final bool isLoading; - final bool isShowAppBar; - final bool hasAppBarParam; - final BaseViewModel baseViewModel; - final bool isBottomBar; - final Widget floatingActionButton; - final bool isPharmacy; - final String title; - final String description; - final String image; - final bool isShowDecPage; - final List infoList; - final Color backgroundColor; - final double preferredSize; - final List appBarIcons; - final PreferredSizeWidget appBarWidget; - - DetailPageScafold( - {@required this.body, - this.appBarTitle = '', - this.isLoading = false, - this.isShowAppBar = false, - this.hasAppBarParam, - this.bottomSheet, - this.baseViewModel, - this.floatingActionButton, - this.isPharmacy = false, - this.title, - this.description, - this.isShowDecPage = true, - this.isBottomBar, - this.backgroundColor, - this.preferredSize = 0.0, - this.appBarIcons, - this.appBarWidget, - this.image, - this.infoList}); - - @override - _DetailPageScafoldState createState() => _DetailPageScafoldState(); -} - -class _DetailPageScafoldState extends State { - AuthenticatedUserObject authenticatedUserObject = - locator(); - - @override - Widget build(BuildContext context) { - AppGlobal.context = context; - PreferredSizeWidget appBar; - - if (this.widget.appBarWidget == null) { - PreferredSizeWidget appBarWidget = AppBarWidget( - widget.appBarTitle, - widget.appBarIcons, - widget.isShowAppBar, - isPharmacy: widget.isPharmacy, - isShowDecPage: widget.isShowDecPage, - image: widget.image, - ); - appBar = widget.preferredSize == 0 - ? appBarWidget - : PreferredSize( - child: appBarWidget, - preferredSize: Size.fromHeight(widget.preferredSize)); - } else { - appBar = this.widget.appBarWidget; - } - - return Scaffold( - backgroundColor: - widget.backgroundColor ?? Theme.of(context).scaffoldBackgroundColor, - appBar: appBar, - body: (!Provider.of(context, listen: false).isLogin && - widget.isShowDecPage) - ? NotAutPage( - title: widget.appBarTitle, - description: widget.description, - infoList: widget.infoList, - ) - : widget.baseViewModel != null - ? NetworkBaseView( - child: buildBodyWidget(), - baseViewModel: widget.baseViewModel, - ) - : buildBodyWidget(), - bottomSheet: widget.bottomSheet, - //floatingActionButton: floatingActionButton ?? floatingActionButton, - // bottomNavigationBar: - // this.isBottomBar == true ? BottomBarSearch() : SizedBox() - // floatingActionButton: FloatingSearchButton(), - ); - } - - buildAppLoaderWidget(bool isLoading) { - return isLoading ? AppLoaderWidget() : Container(); - } - - buildBodyWidget() { - // return body; //Stack(children: [body, buildAppLoaderWidget(isLoading)]); - return Stack(children: [ - widget.body, /*FloatingSearchButton()*/ - ]); - } -} - -class AppBarWidget extends StatelessWidget with PreferredSizeWidget { - final AuthenticatedUserObject authenticatedUserObject = - locator(); - - final String appBarTitle; - final List appBarIcons; - final bool isShowAppBar; - final bool isPharmacy; - final bool isShowDecPage; - final String image; - - AppBarWidget(this.appBarTitle, this.appBarIcons, this.isShowAppBar, - {this.isPharmacy = true, this.isShowDecPage = true, this.image}); - - @override - Widget build(BuildContext context) { - return buildAppBar(context); - } - - Widget buildAppBar(BuildContext context) { - return isShowAppBar - ? AppBar( - elevation: 0, - backgroundColor: Colors.white, -// isPharmacy ? Colors.green : Theme.of(context).appBarTheme.color, - textTheme: TextTheme( - headline6: - TextStyle(color: Colors.white, fontWeight: FontWeight.bold), - ), - title: Texts( - authenticatedUserObject.isLogin || !isShowDecPage - ? appBarTitle.toUpperCase() - : TranslationBase.of(context).serviceInformationTitle, - color: Colors.white, - bold: true, - ), - leading: Builder( - builder: (BuildContext context) { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () => Navigator.pop(context), - child: Icon(Icons.arrow_back_ios, color: Colors.grey), - ); - }, - ), - centerTitle: true, - actions: [ - /// TODO Elham* fix this - if(isPharmacy) - IconButton( - icon: Icon(Icons.shopping_cart), - color: Colors.grey, - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => CartOrderPage()), - ); - }), - image != null - ? InkWell( - onTap: () => Navigator.push( - context, - FadePage( - page: InsuranceUpdate(), - ), - ), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Image.asset( - image, - height: SizeConfig.heightMultiplier * 5, - width: SizeConfig.heightMultiplier * 5, - color: Colors.grey, - ), - ), - ) - : IconButton( - icon: Icon(FontAwesomeIcons.ellipsisV), - color: Colors.grey, - onPressed: () { - settingModalBottomSheet(context); - }, - ), - if (appBarIcons != null) ...appBarIcons - ], - ) - : Container( - height: 0, - width: 0, - ); - } - - @override - Size get preferredSize => Size(double.maxFinite, 60); - - - settingModalBottomSheet(context) { - showModalBottomSheet( - context: context, - builder: (BuildContext bc) { - return Container( - child: new Wrap( - children: [ - new ListTile( - leading: Icon(Icons.shopping_cart), - title: Text( - TranslationBase.of(context).addToCart, - ), - onTap: () => { - if (price > 0) - {addToCartFunction(price, itemID, context)} - else - { - AppToast.showErrorToast( - message: "you should add quantity") - } - }), - ListTile( - leading: Icon(Icons.favorite_border), - title: Text( - TranslationBase.of(context).addToWishlist, - ), - onTap: () => {addToWishlistFunction(itemID)}, - ), - ListTile( - leading: Icon(Icons.compare), - title: Text( - TranslationBase.of(context).compare, - ), - onTap: () => { - Provider.of(context, listen: false) - .addItem(specificationData), - }, - ), - ], - ), - ); - }); - } -} From 7de8c2588fb333e7830332f02f2f7704f71ca7dc Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 16:17:34 +0300 Subject: [PATCH 10/15] 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 a41980b252bcc8f6d2e22e5c523c71d4ad386f7b Mon Sep 17 00:00:00 2001 From: mosazaid Date: Wed, 6 Oct 2021 16:18:08 +0300 Subject: [PATCH 11/15] fix bugs pharmacy wishlist --- .../pharmacyModule/PrescriptionViewModel.dart | 17 +- .../product_detail_view_model.dart | 16 +- lib/pages/landing/landing_page_pharmcy.dart | 157 ++--- .../screens/pharmacy_module_page.dart | 53 +- .../product-details/ProductAppBar.dart | 6 +- .../product-details/product-detail.dart | 587 +++++++++--------- .../product-name-and-price.dart | 2 - .../product-details/recommended_products.dart | 6 +- .../others/app_scafold_detail_page.dart | 3 +- 9 files changed, 433 insertions(+), 414 deletions(-) diff --git a/lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart b/lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart index 45fc8000..86a320e6 100644 --- a/lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/PrescriptionViewModel.dart @@ -13,15 +13,16 @@ class PrescriptionViewModel extends BaseViewModel { _prescriptionService.prescriptionsList; getPrescription() async { - setState(ViewState.Busy); await getSavedLanguage(); - await _prescriptionService.getPrescription(); - if (_prescriptionService.hasError) { - error = _prescriptionService.error; - setState(ViewState.Error); - } else { - setState(ViewState.Idle); + if(prescriptionsList.isNotEmpty){ + setState(ViewState.Busy); + await _prescriptionService.getPrescription(); + if (_prescriptionService.hasError) { + error = _prescriptionService.error; + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } } - } } \ No newline at end of file diff --git a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart index c7ac0a04..9da34312 100644 --- a/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart +++ b/lib/core/viewModels/pharmacyModule/product_detail_view_model.dart @@ -5,6 +5,8 @@ import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/product_detail_service.dart'; import 'package:diplomaticquarterapp/models/pharmacy/specification.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; +import 'package:diplomaticquarterapp/uitl/navigation_service.dart'; import '../../../locator.dart'; @@ -69,8 +71,13 @@ class ProductDetailViewModel extends BaseViewModel{ Future addToWishlistData(itemID) async { hasError = false; - setState(ViewState.Busy); + setState(ViewState.BusyLocal); + GifLoaderDialogUtils.showMyDialog( + locator().navigatorKey.currentContext); await _productDetailService.addToWishlist(itemID); + GifLoaderDialogUtils.hideDialog( + locator().navigatorKey.currentContext); + if (_productDetailService.hasError) { error = _productDetailService.error; setState(ViewState.ErrorLocal); @@ -92,8 +99,13 @@ class ProductDetailViewModel extends BaseViewModel{ Future deletWishlistData(itemID) async { hasError = false; - setState(ViewState.Busy); + setState(ViewState.BusyLocal); + GifLoaderDialogUtils.showMyDialog( + locator().navigatorKey.currentContext); await _productDetailService.delteItemFromWishlist(itemID); + GifLoaderDialogUtils.hideDialog( + locator().navigatorKey.currentContext); + if (_productDetailService.hasError) { error = _productDetailService.error; setState(ViewState.ErrorLocal); diff --git a/lib/pages/landing/landing_page_pharmcy.dart b/lib/pages/landing/landing_page_pharmcy.dart index 4927c163..41c4b694 100644 --- a/lib/pages/landing/landing_page_pharmcy.dart +++ b/lib/pages/landing/landing_page_pharmcy.dart @@ -49,88 +49,93 @@ class _LandingPagePharmacyState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: currentTab != 4 && currentTab != 3 - ? AppBar( - backgroundColor: Color(0xff5AB145), - elevation: 0, - title: Container( - height: MediaQuery.of(context).size.height * 0.056, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5.0), - color: Colors.white, - ), - child: InkWell( - child: Padding( - padding: EdgeInsets.all(5.0), - child: Row( - //crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Icon(Icons.search, size: 25.0), - SizedBox( - width: 15.0, - ), - Texts( - TranslationBase.of(context).searchProductHere, - fontSize: 13, - ) - ], + return WillPopScope( + onWillPop: ()async{ + return false; + }, + child: Scaffold( + appBar: currentTab != 4 && currentTab != 3 + ? AppBar( + backgroundColor: Color(0xff5AB145), + elevation: 0, + title: Container( + height: MediaQuery.of(context).size.height * 0.056, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5.0), + color: Colors.white, + ), + child: InkWell( + child: Padding( + padding: EdgeInsets.all(5.0), + child: Row( + //crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Icon(Icons.search, size: 25.0), + SizedBox( + width: 15.0, + ), + Texts( + TranslationBase.of(context).searchProductHere, + fontSize: 13, + ) + ], + ), ), + onTap: () { + Navigator.push( + context, + FadePage(page: SearchProductsPage()), + ); + }, ), - onTap: () { - Navigator.push( - context, - FadePage(page: SearchProductsPage()), + ), + leading: Builder( + builder: (BuildContext context) { + return InkWell( + onTap: () { + setState(() { + currentTab = 0; + pageController.jumpToPage(0); + }); + }, + child: Container( + height: 2.0, + width: 10.0, + child: Image.asset( + 'assets/images/pharmacy_logo.png', + ), + ), ); }, ), - ), - leading: Builder( - builder: (BuildContext context) { - return InkWell( - onTap: () { - setState(() { - currentTab = 0; - pageController.jumpToPage(0); - }); - }, - child: Container( - height: 2.0, - width: 10.0, - child: Image.asset( - 'assets/images/pharmacy_logo.png', + actions: [ + IconButton( + // iconSize: 70, + icon: Image.asset( + 'assets/images/new-design/qr-code.png', ), - ), - ); - }, - ), - actions: [ - IconButton( - // iconSize: 70, - icon: Image.asset( - 'assets/images/new-design/qr-code.png', - ), - onPressed: _scanQrAndGetProduct //do something, - ) - ], - centerTitle: true, - ) - : null, - extendBody: false, - body: PageView( - physics: NeverScrollableScrollPhysics(), - controller: pageController, - children: [ - PharmacyPage(), - PharmacyCategorisePage(), - PharmacyProfilePage(), - CartOrderPage(), - ], - ), - bottomNavigationBar: BottomNavPharmacyBar( - changeIndex: _changeCurrentTab, - index: currentTab, + onPressed: _scanQrAndGetProduct //do something, + ) + ], + centerTitle: true, + ) + : null, + extendBody: false, + body: PageView( + physics: NeverScrollableScrollPhysics(), + controller: pageController, + children: [ + PharmacyPage(), + PharmacyCategorisePage(), + PharmacyProfilePage(), + CartOrderPage(), + ], + ), + bottomNavigationBar: BottomNavPharmacyBar( + changeIndex: _changeCurrentTab, + index: currentTab, + ), ), ); } diff --git a/lib/pages/pharmacies/screens/pharmacy_module_page.dart b/lib/pages/pharmacies/screens/pharmacy_module_page.dart index c158341d..ecc39d6c 100644 --- a/lib/pages/pharmacies/screens/pharmacy_module_page.dart +++ b/lib/pages/pharmacies/screens/pharmacy_module_page.dart @@ -46,31 +46,36 @@ class _PharmacyPageState extends State { @override Widget build(BuildContext context) { - return BaseView( - onModelReady: (model) async { - await model.getSavedLanguage(); - await model.getBannerList(); + return WillPopScope( + onWillPop: ()async{ + return false; }, - allowAny: true, - builder: (_, model, wi) => AppScaffold( - title: "", - isShowAppBar: false, - isShowDecPage: false, - baseViewModel: model, - backgroundColor: Colors.white, - body: Container( - width: double.infinity, - child: SingleChildScrollView( - child: Column( - //crossAxisAlignment: CrossAxisAlignment.start, - children: [ - BannerPager(model), - GridViewButtons(model), - PrescriptionsWidget(), - ShopByBrandWidget(), - RecentlyViewedWidget(), - BestSellerWidget(), - ], + child: BaseView( + onModelReady: (model) async { + await model.getSavedLanguage(); + await model.getBannerList(); + }, + allowAny: true, + builder: (_, model, wi) => AppScaffold( + title: "", + isShowAppBar: false, + isShowDecPage: false, + baseViewModel: model, + backgroundColor: Colors.white, + body: Container( + width: double.infinity, + child: SingleChildScrollView( + child: Column( + //crossAxisAlignment: CrossAxisAlignment.start, + children: [ + BannerPager(model), + GridViewButtons(model), + PrescriptionsWidget(), + ShopByBrandWidget(), + RecentlyViewedWidget(), + BestSellerWidget(), + ], + ), ), ), ), diff --git a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart index 2fad8016..95332bc5 100644 --- a/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart +++ b/lib/pages/pharmacies/screens/product-details/ProductAppBar.dart @@ -1,5 +1,6 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; +import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/product_detail_view_model.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'; @@ -15,8 +16,9 @@ import 'CustomIcon.dart'; class ProductAppBar extends StatelessWidget with PreferredSizeWidget { final PharmacyProduct product; + final ProductDetailViewModel model; - ProductAppBar({Key key, this.product}) : super(key: key); + ProductAppBar({Key key, this.product, this.model}) : super(key: key); AuthenticatedUserObject authenticatedUserObject = locator(); @@ -112,7 +114,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget { title: Text( TranslationBase.of(context).addToWishlist, ), - onTap: () => {addToWishlistFunction(itemID)}, + onTap: () => {model.addToWishlistData(itemID)}, ), ListTile( leading: Icon(Icons.compare), diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 5e8f4dd5..c430d08d 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -1,28 +1,19 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.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/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/compare-list.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-name-and-price.dart'; -import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/recommended_products.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/reviews_info.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/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; -import 'package:diplomaticquarterapp/widgets/others/app_scafold_detail_page.dart'; import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart'; -import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; -import 'package:rating_bar/rating_bar.dart'; -import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.dart'; -import '../cart-order-page.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'ProductAppBar.dart'; @@ -105,300 +96,307 @@ class __ProductDetailPageState extends State ProjectViewModel projectViewModel = Provider.of(context); final screenSize = MediaQuery.of(context).size; - return AppScaffold( - appBarTitle: TranslationBase.of(context).productDetails, - isShowAppBar: true, - isPharmacy: true, - isShowDecPage: false, - customAppBar: ProductAppBar(product: widget.product,), - body: SingleChildScrollView( - child: Column( - children: [ - Container( - width: double.infinity, - color: Colors.white, - child: Column( - children: [ - if (widget.product.images.isNotEmpty) + return BaseView( + builder: (_, model, wi) => AppScaffold( + appBarTitle: TranslationBase.of(context).productDetails, + isShowAppBar: true, + isPharmacy: true, + baseViewModel: model, + isShowDecPage: false, + customAppBar: ProductAppBar(product: widget.product,), + body: SingleChildScrollView( + child: Column( + children: [ + 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) + ], + ), + ), + SizedBox( + height: 4, + ), + Container( + color: Colors.white, + child: ProductNameAndPrice( + context, + widget.product, + customerId: customerId, + addToWishlistFunction: (item) { + model.addToWishlistData(itemID); + setState(() { + + }); + }, + deleteFromWishlistFunction: (item) { + model.deletWishlistData(itemID); + setState(() { + + }); + }, + notifyMeWhenAvailable: (context, itemId) { + notifyMeWhenAvailable(context, itemId); + }, + isInWishList: isInWishList, + ), + ), + SizedBox( + height: 6, + ), + Container( + color: Colors.white, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ Container( - height: MediaQuery.of(context).size.height * .40, - child: Image.network( - widget.product.images[0].src.trim(), - fit: BoxFit.contain, + padding: EdgeInsets.symmetric( + vertical: 15, horizontal: 10), + child: Texts( + TranslationBase.of(context).specification, + fontSize: 15, + fontWeight: FontWeight.bold, ), + width: double.infinity, ), - if (widget.product.discountDescription != null) - DiscountDescription(product: widget.product) - ], + // Divider(color: Colors.grey), + ], + ), ), - ), - SizedBox( - height: 4, - ), - Container( - color: Colors.white, - child: ProductNameAndPrice( - context, - widget.product, - customerId: customerId, - addToWishlistFunction: (item) { - addToWishlistFunction(item); - setState(() {}); - }, - deleteFromWishlistFunction: (item) { - deleteFromWishlistFunction(item); - setState(() {}); - }, - notifyMeWhenAvailable: (context, itemId) { - notifyMeWhenAvailable(context, itemId); - }, - isInWishList: isInWishList, + SizedBox( + height: 6, ), - ), - 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, - ), - width: double.infinity, - ), - // Divider(color: Colors.grey), - ], + // Container( + // height: 500, + // color: Colors.white, + // child: Scaffold( + // backgroundColor: Colors.white, + // extendBodyBehindAppBar: false, + // appBar: PreferredSize( + // preferredSize: Size.fromHeight( + // MediaQuery.of(context).size.height * 0.070), + // child: Container( + // height: MediaQuery.of(context).size.height * 0.070, + // decoration: BoxDecoration( + // border: Border( + // bottom: BorderSide( + // color: Theme.of(context).dividerColor, + // width: 0.5), //width: 0.7 + // ), + // color: Colors.white), + // child: Center( + // child: TabBar( + // isScrollable: false, + // controller: _tabController, + // // indicatorColor: Colors.transparent, + // indicatorWeight: 1.0, + // indicatorSize: TabBarIndicatorSize.tab, + // indicatorColor:Colors.green, + // labelColor: Theme.of(context).primaryColor, + // labelPadding: EdgeInsets.only( + // top: 0, left: 0, right: 0, bottom: 0), + // unselectedLabelColor: Colors.grey[800], + // tabs: [ + // tabWidget(screenSize, _activeTab == 0, + // TranslationBase.of(context).details, + // ), + // tabWidget(screenSize, _activeTab == 1, + // TranslationBase.of(context).review, + // ), + // tabWidget(screenSize, _activeTab == 2, + // TranslationBase.of(context).availability), + // ], + // ), + // ), + // ), + // ), + // body: Column( + // children: [ + // Expanded( + // child: TabBarView( + // physics: BouncingScrollPhysics(), + // controller: _tabController, + // children: [ + // DetailsInfo( + // product: widget.product, + // ), + // ReviewsInfo( + // product: widget.product, + // ), + // AvailabilityInfo() + // ], + // ), + // ), + // + // ], + // ), + // ), + // ), + + SizedBox( + height: 6, ), - ), - SizedBox( - height: 6, - ), - // Container( - // height: 500, - // color: Colors.white, - // child: Scaffold( - // backgroundColor: Colors.white, - // extendBodyBehindAppBar: false, - // appBar: PreferredSize( - // preferredSize: Size.fromHeight( - // MediaQuery.of(context).size.height * 0.070), - // child: Container( - // height: MediaQuery.of(context).size.height * 0.070, - // decoration: BoxDecoration( - // border: Border( - // bottom: BorderSide( - // color: Theme.of(context).dividerColor, - // width: 0.5), //width: 0.7 - // ), - // color: Colors.white), - // child: Center( - // child: TabBar( - // isScrollable: false, - // controller: _tabController, - // // indicatorColor: Colors.transparent, - // indicatorWeight: 1.0, - // indicatorSize: TabBarIndicatorSize.tab, - // indicatorColor:Colors.green, - // labelColor: Theme.of(context).primaryColor, - // labelPadding: EdgeInsets.only( - // top: 0, left: 0, right: 0, bottom: 0), - // unselectedLabelColor: Colors.grey[800], - // tabs: [ - // tabWidget(screenSize, _activeTab == 0, - // TranslationBase.of(context).details, - // ), - // tabWidget(screenSize, _activeTab == 1, - // TranslationBase.of(context).review, - // ), - // tabWidget(screenSize, _activeTab == 2, - // TranslationBase.of(context).availability), - // ], - // ), - // ), - // ), - // ), - // body: Column( - // children: [ - // Expanded( - // child: TabBarView( - // physics: BouncingScrollPhysics(), - // controller: _tabController, - // children: [ - // DetailsInfo( - // product: widget.product, - // ), - // ReviewsInfo( - // product: widget.product, - // ), - // AvailabilityInfo() - // ], - // ), - // ), - // - // ], - // ), - // ), - // ), - - SizedBox( - height: 6, - ), - - //TODO Elham* Remove this - 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), + + //TODO Elham* Remove this + 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, ), - color: Colors.white, - ), - CustomDivider( - color: isDetails - ? Colors.green - : Colors.transparent, - ) - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () { - setState(() { - isDetails = false; - isReviews = true; - isAvailability = false; - }); - }, - child: Text( - TranslationBase.of(context).reviews, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold), + CustomDivider( + color: isDetails + ? Colors.green + : Colors.transparent, + ) + ], + ), + SizedBox( + width: 20, + ), + Column( + children: [ + FlatButton( + onPressed: () { + setState(() { + isDetails = false; + isReviews = true; + isAvailability = false; + }); + }, + child: Text( + TranslationBase.of(context).reviews, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold), + ), + color: Colors.white, ), - color: Colors.white, - ), - CustomDivider( - color: isReviews - ? Colors.green - : Colors.transparent, - ), - ], - ), - SizedBox( - width: 20, - ), - Column( - children: [ - FlatButton( - onPressed: () { - setState(() { - isDetails = false; - isReviews = false; - isAvailability = true; - }); - }, - child: Text( - TranslationBase.of(context).availability, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold), + CustomDivider( + color: isReviews + ? 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, - ) - : isAvailability - ? AvailabilityInfo() - : Container(), - ], + ], + ), + SizedBox( + width: 20, + ), + Column( + children: [ + FlatButton( + onPressed: () { + 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, + ), + ], + ), + ], + ), + SizedBox( + height: 10, + ), + isDetails + ? DetailsInfo( + product: widget.product, + ) + : isReviews + ? ReviewsInfo( + product: widget.product, + ) + : isAvailability + ? AvailabilityInfo() + : Container(), + ], + ), ), - ), - - ///TODO Elham* check if we need recommanded - // Row( - // children: [ - // customerId != null - // ? Container( - // width: 410, - // height: 50, - // color: Colors.white, - // child: Texts( - // TranslationBase.of(context).recommended, - // bold: true, - // ), - // ) - // : Container(), - // ], - // ), - // RecommendedProducts(product: widget.product) - - SizedBox( - height: 80, - ) - ], + + ///TODO Elham* check if we need recommanded + // Row( + // children: [ + // customerId != null + // ? Container( + // width: 410, + // height: 50, + // color: Colors.white, + // child: Texts( + // TranslationBase.of(context).recommended, + // bold: true, + // ), + // ) + // : Container(), + // ], + // ), + // RecommendedProducts(product: widget.product) + + SizedBox( + height: 80, + ) + ], + ), + ), + bottomSheet: FooterWidget( + widget.product.stockAvailability != 'Out of stock', + widget.product.orderMaximumQuantity, + widget.product.orderMinimumQuantity, + widget.product.stockQuantity, + widget.product, + price: price, + isOverQuantity: isOverQuantity, + addToCartFunction: addToCartFunction, ), ), - bottomSheet: FooterWidget( - widget.product.stockAvailability != 'Out of stock', - widget.product.orderMaximumQuantity, - widget.product.orderMinimumQuantity, - widget.product.stockQuantity, - widget.product, - price: price, - isOverQuantity: isOverQuantity, - addToCartFunction: addToCartFunction, - ), - ); + ); } } @@ -443,13 +441,8 @@ notifyMeWhenAvailable(context, itemId) async { await x.notifyMe(customerId, itemId); } -addToWishlistFunction(itemID) async { - ProductDetailViewModel x = new ProductDetailViewModel(); - isInWishList = true; - await x.addToWishlistData(itemID); -} - deleteFromWishlistFunction(itemID) async { + ProductDetailViewModel x = new ProductDetailViewModel(); isInWishList = false; await x.deletWishlistData(itemID); 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 619a4fb1..670b3c71 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 @@ -93,10 +93,8 @@ class _ProductNameAndPriceState extends State { { 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); diff --git a/lib/pages/pharmacies/screens/product-details/recommended_products.dart b/lib/pages/pharmacies/screens/product-details/recommended_products.dart index f40f1f08..2f56bf83 100644 --- a/lib/pages/pharmacies/screens/product-details/recommended_products.dart +++ b/lib/pages/pharmacies/screens/product-details/recommended_products.dart @@ -1,6 +1,7 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.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/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/screens/product-details/product-detail.dart'; @@ -14,8 +15,9 @@ import 'package:rating_bar/rating_bar.dart'; class RecommendedProducts extends StatefulWidget { final PharmacyProduct product; + final ProductDetailViewModel productDetailModel; - const RecommendedProducts({Key key, this.product}) : super(key: key); + const RecommendedProducts({Key key, this.product, this.productDetailModel}) : super(key: key); @override _RecommendedProductsState createState() => _RecommendedProductsState(); @@ -146,7 +148,7 @@ class _RecommendedProductsState extends State { true) { GifLoaderDialogUtils.showMyDialog( context); - await addToWishlistFunction(model + await widget.productDetailModel.addToWishlistData(model .recommendedProductList[index] .id); // checkWishlist(); diff --git a/lib/widgets/others/app_scafold_detail_page.dart b/lib/widgets/others/app_scafold_detail_page.dart index 595e0872..fad30c41 100644 --- a/lib/widgets/others/app_scafold_detail_page.dart +++ b/lib/widgets/others/app_scafold_detail_page.dart @@ -3,6 +3,7 @@ import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/viewModels/base_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/pages/insurance/insurance_update_screen.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; @@ -261,7 +262,7 @@ class AppBarWidget extends StatelessWidget with PreferredSizeWidget { title: Text( TranslationBase.of(context).addToWishlist, ), - onTap: () => {addToWishlistFunction(itemID)}, + onTap: () => {locator().addToWishlistData(itemID)}, ), ListTile( leading: Icon(Icons.compare), From 8b5e1e57c73ebeda96310391e0a8a8abe11a19b5 Mon Sep 17 00:00:00 2001 From: mosazaid Date: Wed, 6 Oct 2021 16:24:17 +0300 Subject: [PATCH 12/15] fix bugs pharmacy wishlist --- .../product-details/product-detail.dart | 6 +- .../product-details/recommended_products.dart | 352 ------------------ 2 files changed, 1 insertion(+), 357 deletions(-) delete mode 100644 lib/pages/pharmacies/screens/product-details/recommended_products.dart diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index f3524b35..cec56f5d 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -20,8 +20,6 @@ import 'discount_description.dart'; import 'footor/footer-widget.dart'; import 'shared/product_details_app_bar.dart'; - - String itemID; PharmacyProduct specificationData; @@ -338,6 +336,4 @@ addToCartFunction({quantity, itemID, BuildContext context,ProductDetailViewModel 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/recommended_products.dart b/lib/pages/pharmacies/screens/product-details/recommended_products.dart deleted file mode 100644 index 7222ad85..00000000 --- a/lib/pages/pharmacies/screens/product-details/recommended_products.dart +++ /dev/null @@ -1,352 +0,0 @@ -import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; -import 'package:diplomaticquarterapp/core/model/pharmacies/recommendedProduct_model.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/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'; -import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; -import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; -import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:rating_bar/rating_bar.dart'; - -class RecommendedProducts extends StatefulWidget { - final PharmacyProduct product; - final String customerId; - final ProductDetailViewModel productDetailViewModel; - final bool isOverQuantity; - final bool isInWishList; - final Function addToWishlistFunction; - final Function deleteFromWishlistFunction; - - RecommendedProducts( - {Key key, - this.product, - this.productDetailViewModel, - this.customerId, - this.isOverQuantity = false, - this.isInWishList = false, - this.addToWishlistFunction, - this.deleteFromWishlistFunction}) - : super(key: key); - - @override - _RecommendedProductsState createState() => _RecommendedProductsState(); -} - -class _RecommendedProductsState extends State { - @override - Widget build(BuildContext context) { - ProjectViewModel projectViewModel = Provider.of(context); - return SingleChildScrollView( - child: Container( - width: 410, - color: Colors.white, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - color: Colors.white, - height: 210, - margin: EdgeInsets.only(bottom: 75), - padding: EdgeInsets.only(bottom: 5), - // margin: EdgeInsets.symmetric(horizontal: 6, vertical: 4), - child: BaseView( - onModelReady: (model) => - model.getRecommendedProducts(widget.product.id), - builder: (_, model, wi) => Container( - child: model.recommendedProductList.length != null - ? ListView.builder( - scrollDirection: Axis.horizontal, - shrinkWrap: true, - physics: ScrollPhysics(), - // physics: NeverScrollableScrollPhysics(), - itemCount: model.recommendedProductList.length, - itemBuilder: (context, index) { - return InkWell( - onTap: () async { - GifLoaderDialogUtils.showMyDialog(context); - RecommendedProductModel data = - model.recommendedProductList[index]; - var json = data.toJson(); - PharmacyProduct product = - new PharmacyProduct.fromJson(json); - await Navigator.pushReplacement( - context, - FadePage( - page: ProductDetailPage(product), - ), - ); - GifLoaderDialogUtils.hideDialog(context); - }, - child: Card( - elevation: 2, - shape: RoundedRectangleBorder( - side: BorderSide( - color: Colors.grey[300], width: 2), - borderRadius: BorderRadius.circular(10), - ), - margin: EdgeInsets.symmetric( - horizontal: 8, - vertical: 0, - ), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all( - Radius.circular(15), - ), - ), - padding: EdgeInsets.symmetric(horizontal: 4), - width: MediaQuery.of(context).size.width / 3, - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Stack(children: [ - Container( - 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, - 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); - setState(() { - model - .recommendedProductList[ - index] - .isinwishlist = true; - }); - } else { - GifLoaderDialogUtils - .showMyDialog(context); - await widget.deleteFromWishlistFunction( - itemID: model - .recommendedProductList[ - index] - .id, - model: widget - .productDetailViewModel); - GifLoaderDialogUtils - .hideDialog(context); - setState(() { - model - .recommendedProductList[ - index] - .isinwishlist = false; - }); - } - } else { - return; - } - setState(() { - // checkWishlist(); - }); - }, - ), - ), - ), - Container( - margin: EdgeInsets.fromLTRB( - 0, 16, 10, 16), - alignment: Alignment.center, - child: (model - .recommendedProductList[ - index] - .images != - null && - model - .recommendedProductList[ - index] - .images - .length > - 0) - ? Image.network( - model - .recommendedProductList[ - index] - .images[0] - .src - .toString(), - fit: BoxFit.cover, - height: 60, - ) - : Image.asset( - "assets/images/no_image.png", - fit: BoxFit.cover, - height: 60, - ), - ), - Container( - width: model - .recommendedProductList[ - index] - .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: model - .recommendedProductList[ - index] - .rxMessage != - null - ? Texts( - projectViewModel.isArabic - ? model - .recommendedProductList[ - index] - .rxMessagen - : model - .recommendedProductList[ - index] - .rxMessage, - color: Colors.white, - regular: true, - fontSize: 10, - fontWeight: FontWeight.w400, - ) - : Texts(""), - ), - ]), - Container( - margin: EdgeInsets.symmetric( - horizontal: 6, - vertical: 0, - ), - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - projectViewModel.isArabic - ? model - .recommendedProductList[ - index] - .namen - : model - .recommendedProductList[ - index] - .name, - style: TextStyle( - 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 ${model.recommendedProductList[index].price}", - bold: true, - fontSize: 14, - ), - ), - ], - ), - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Container( - padding: - EdgeInsets.only(right: 10), - child: Align( - alignment: Alignment.topLeft, - child: RatingBar.readOnly( - initialRating: model - .recommendedProductList[ - index] - .approvedRatingSum - .toDouble(), - size: 13.0, - filledColor: - Colors.yellow[700], - emptyColor: Colors.grey[500], - isHalfAllowed: true, - halfFilledIcon: - Icons.star_half, - filledIcon: Icons.star, - emptyIcon: Icons.star, - ), - ), - ), - Texts( - "(${model.recommendedProductList[index].notApprovedTotalReviews.toString()})", -// bold: true, - fontSize: 12, - ), - ]), - ], - ), - ), - ), - ); - }) - : Container( - // color: Colors.white, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - // crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Texts( - TranslationBase.of(context).nonRecommended, - color: Colors.black, - ), - ], - ), - ), - ), - ), - ), - ], - ), - ), - ); - } -} From 92540041253d3782982852ad4f1c9d245b4f45c0 Mon Sep 17 00:00:00 2001 From: Elham Rababh Date: Wed, 6 Oct 2021 16:26:27 +0300 Subject: [PATCH 13/15] 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 14/15] 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 15/15] 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];