Merge branch 'product_detail_page' into 'development'

Product detail page

See merge request Cloud_Solution/diplomatic-quarter!420
merge-requests/421/merge
Mohammad Aljammal 3 years ago
commit d2be206d6c

@ -1555,6 +1555,7 @@ const Map localizedValues = {
"quantitySize": {"en": "Quantity", "ar": "كميه"}, "quantitySize": {"en": "Quantity", "ar": "كميه"},
"addToCart": {"en": "Add to Cart", "ar": "إضف للسلة"}, "addToCart": {"en": "Add to Cart", "ar": "إضف للسلة"},
"addToWishlist": {"en": "Add to Wishlist", "ar": "اضف للمفضلة"}, "addToWishlist": {"en": "Add to Wishlist", "ar": "اضف للمفضلة"},
"removeFromWishlist": {"en": "Remove From Wishlist", "ar": "احذف للمفضلة"},
"noData": {"en": "There is no data", "ar": "لايوجد بيانات"}, "noData": {"en": "There is no data", "ar": "لايوجد بيانات"},
"no_data": {"en": "No data", "ar": "لايوجد بيانات"}, "no_data": {"en": "No data", "ar": "لايوجد بيانات"},
"buyNow": {"en": "buy now", "ar": "إشتري الان"}, "buyNow": {"en": "buy now", "ar": "إشتري الان"},

@ -97,12 +97,12 @@ class ProductDetailViewModel extends BaseViewModel{
} }
Future deletWishlistData(itemID) async { Future deleteWishlistData(itemID) async {
hasError = false; hasError = false;
setState(ViewState.BusyLocal); setState(ViewState.BusyLocal);
GifLoaderDialogUtils.showMyDialog( GifLoaderDialogUtils.showMyDialog(
locator<NavigationService>().navigatorKey.currentContext); locator<NavigationService>().navigatorKey.currentContext);
await _productDetailService.delteItemFromWishlist(itemID); await _productDetailService.deleteItemFromWishlist(itemID);
GifLoaderDialogUtils.hideDialog( GifLoaderDialogUtils.hideDialog(
locator<NavigationService>().navigatorKey.currentContext); locator<NavigationService>().navigatorKey.currentContext);
@ -125,4 +125,10 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.Idle); setState(ViewState.Idle);
} }
clearReview(){
productDetailService.clear();
}
} }

@ -87,7 +87,7 @@ class _ProductCheckTypeWidgetState extends State<ProductCheckTypeWidget> {
deleteWishListItem(itemID) async { deleteWishListItem(itemID) async {
ProductDetailViewModel x = new ProductDetailViewModel(); ProductDetailViewModel x = new ProductDetailViewModel();
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await x.deletWishlistData(itemID); await x.deleteWishlistData(itemID);
setState(() setState(()
async{ async{
await await

@ -31,7 +31,7 @@ class FooterWidget extends StatefulWidget {
} }
class _FooterWidgetState extends State<FooterWidget> { class _FooterWidgetState extends State<FooterWidget> {
double quantityUI = 70; double quantityUI = 80;
bool showUI = false; bool showUI = false;
AuthenticatedUserObject authenticatedUserObject = AuthenticatedUserObject authenticatedUserObject =
locator<AuthenticatedUserObject>(); locator<AuthenticatedUserObject>();
@ -77,7 +77,7 @@ class _FooterWidgetState extends State<FooterWidget> {
child: Icon(Icons.close, color: Colors.black), child: Icon(Icons.close, color: Colors.black),
onTap: () { onTap: () {
setState(() { setState(() {
quantityUI = 70; quantityUI = 80;
showUI = false; showUI = false;
}); });
}, },
@ -172,7 +172,7 @@ class _FooterWidgetState extends State<FooterWidget> {
onPressed: () { onPressed: () {
setState(() { setState(() {
if (showUI) { if (showUI) {
quantityUI = 70; quantityUI = 80;
showUI = false; showUI = false;
} else { } else {
quantityUI = 150; quantityUI = 150;
@ -189,7 +189,7 @@ class _FooterWidgetState extends State<FooterWidget> {
disabled: !widget.isAvailable && widget.quantity > 0 || disabled: !widget.isAvailable && widget.quantity > 0 ||
widget.quantity > widget.quantityLimit || widget.quantity > widget.quantityLimit ||
widget.item.rxMessage != null, widget.item.rxMessage != null,
disableColor: Colors.green[400], disableColor: Color(0xFF4CAF50),
onTap: () async { onTap: () async {
if (!authenticatedUserObject.isLogin) { if (!authenticatedUserObject.isLogin) {
Navigator.of(context).pushNamed( Navigator.of(context).pushNamed(
@ -199,8 +199,9 @@ class _FooterWidgetState extends State<FooterWidget> {
await widget.addToCartFunction( await widget.addToCartFunction(
widget.quantity, widget.item.id, context); widget.quantity, widget.item.id, context);
}, },
borderColor: Color(0xFF4CAF50),
borderRadius: 5, borderRadius: 5,
color: Colors.green, color: Color(0xFF4CAF50),
), ),
), ),
SizedBox( SizedBox(

@ -45,7 +45,6 @@ class __ProductDetailPageState extends State<ProductDetailPage>{
bool isInWishList = false; bool isInWishList = false;
int quantity = 0; int quantity = 0;
checkWishlist() async { checkWishlist() async {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
ProductDetailViewModel model = new ProductDetailViewModel(); ProductDetailViewModel model = new ProductDetailViewModel();
@ -96,11 +95,15 @@ class __ProductDetailPageState extends State<ProductDetailPage>{
isShowDecPage: false, isShowDecPage: false,
customAppBar: ProductAppBar( customAppBar: ProductAppBar(
product: widget.product, product: widget.product,
quantity: quantity,
model: model, model: model,
addToWishlistFunction: (item) { addToWishlistFunction: () async {
addToWishlistFunction(itemID:item,model:model); await addToWishlistFunction(itemID: itemID, model: model);
setState(() {}); },
deleteFromWishlistFunction: () async {
await deleteFromWishlistFunction(itemID: itemID, model: model);
}, },
isInWishList:isInWishList
), ),
body: SingleChildScrollView( body: SingleChildScrollView(
child: Column( child: Column(
@ -137,11 +140,15 @@ class __ProductDetailPageState extends State<ProductDetailPage>{
setState(() {}); setState(() {});
}, },
deleteFromWishlistFunction: (item) { deleteFromWishlistFunction: (item) {
deleteFromWishlistFunction(itemID: item, model: model); deleteFromWishlistFunction(
itemID: item, model: model);
setState(() {}); setState(() {});
}, },
notifyMeWhenAvailable: (context, itemId) { notifyMeWhenAvailable: (context, itemId) {
notifyMeWhenAvailable(itemId:itemId, customerId: customerId, model: model); notifyMeWhenAvailable(
itemId: itemId,
customerId: customerId,
model: model);
}, },
isInWishList: isInWishList, isInWishList: isInWishList,
), ),
@ -214,12 +221,16 @@ class __ProductDetailPageState extends State<ProductDetailPage>{
children: [ children: [
FlatButton( FlatButton(
onPressed: () async { onPressed: () async {
if(widget.product.approvedTotalReviews>0) { if (widget.product.approvedTotalReviews >
0) {
GifLoaderDialogUtils.showMyDialog( GifLoaderDialogUtils.showMyDialog(
context); context);
await model.getProductReviewsData( await model.getProductReviewsData(
widget.product.id); widget.product.id);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(
context);
} else {
model.clearReview();
} }
setState(() { setState(() {
isDetails = false; isDetails = false;
@ -319,21 +330,27 @@ class __ProductDetailPageState extends State<ProductDetailPage>{
addToWishlistFunction({itemID, ProductDetailViewModel model}) async { addToWishlistFunction({itemID, ProductDetailViewModel model}) async {
isInWishList = true; isInWishList = true;
await model.addToWishlistData(itemID); await model.addToWishlistData(itemID);
setState(() {});
} }
deleteFromWishlistFunction({itemID, ProductDetailViewModel model}) async { deleteFromWishlistFunction({itemID, ProductDetailViewModel model}) async {
isInWishList = false; isInWishList = false;
await model.deletWishlistData(itemID); await model.deleteWishlistData(itemID);
setState(() {});
} }
} }
addToCartFunction(
addToCartFunction({quantity, itemID, BuildContext context,ProductDetailViewModel model}) async { {quantity,
itemID,
BuildContext context,
ProductDetailViewModel model}) async {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
await model.addToCartData(quantity, itemID); await model.addToCartData(quantity, itemID);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
} }
notifyMeWhenAvailable({itemId, customerId,ProductDetailViewModel model }) async { notifyMeWhenAvailable(
{itemId, customerId, ProductDetailViewModel model}) async {
await model.notifyMe(customerId, itemId); await model.notifyMe(customerId, itemId);
} }

@ -68,8 +68,8 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
widget.item.stockAvailability == 'Out of stock' && widget.item.stockAvailability == 'Out of stock' &&
widget.customerId != null widget.customerId != null
? InkWell( ? InkWell(
onTap: () => onTap: () => widget.notifyMeWhenAvailable(
widget.notifyMeWhenAvailable(context, widget.item.id), context, widget.item.id),
child: Row(children: [ child: Row(children: [
Texts( Texts(
TranslationBase.of(context).notifyMe, TranslationBase.of(context).notifyMe,
@ -88,13 +88,17 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
icon: !widget.isInWishList icon: !widget.isInWishList
? Icons.favorite_border ? Icons.favorite_border
: Icons.favorite, : Icons.favorite,
color: !widget.isInWishList ? Colors.white : Colors.red, color: !widget.isInWishList
? Colors.white
: Colors.red[800],
onPress: () async { onPress: () async {
{ {
if (widget.customerId != null) { if (widget.customerId != null) {
if (!widget.isInWishList) { if (!widget.isInWishList) {
await widget await widget
.addToWishlistFunction(widget.item.id); .addToWishlistFunction(widget.item.id);
} else { } else {
await widget await widget
.deleteFromWishlistFunction(widget.item.id); .deleteFromWishlistFunction(widget.item.id);
@ -161,29 +165,32 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
"(${widget.item.approvedTotalReviews}${TranslationBase.of(context).review})", "(${widget.item.approvedTotalReviews}${TranslationBase.of(context).review})",
fontSize: 12, fontSize: 12,
), ),
], SizedBox(
), width: 70,
),
), ),
Expanded( if (widget.item.rxMessage != null)
flex: 1, Row(
child: Container( children: [
child: widget.item.rxMessage != null Text(
? Text(
projectViewModel.isArabic projectViewModel.isArabic
? widget.item.rxMessagen.toString() ? widget.item.rxMessagen.toString()
: widget.item.rxMessage.toString(), : widget.item.rxMessage.toString(),
style: TextStyle(color: Colors.red, fontSize: 10), style: TextStyle(color: Colors.red, fontSize: 10),
)
: Container()),
), ),
widget.item.rxMessage != null SizedBox(
? Icon( width: 5,
),
Icon(
FontAwesomeIcons.questionCircle, FontAwesomeIcons.questionCircle,
color: Colors.red, color: Colors.red,
size: 15.0, size: 15.0,
) )
: Container(), ],
)
],
),
),
),
], ],
), ),
), ),

@ -8,7 +8,8 @@ class ReviewsInfo extends StatelessWidget {
final PharmacyProduct product; final PharmacyProduct product;
final ProductDetailViewModel previousModel; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -31,8 +32,8 @@ class ReviewsInfo extends StatelessWidget {
children: [ children: [
Container( Container(
child: Text( child: Text(
previousModel.productDetailService[0].reviews[index] previousModel.productDetailService[0]
.customerId .reviews[index].customerId
.toString(), .toString(),
style: TextStyle( style: TextStyle(
fontSize: 17, fontSize: 17,
@ -43,8 +44,8 @@ class ReviewsInfo extends StatelessWidget {
Container( Container(
margin: EdgeInsets.only(left: 210), margin: EdgeInsets.only(left: 210),
child: RatingBar.readOnly( child: RatingBar.readOnly(
initialRating: previousModel.productDetailService[0] initialRating: previousModel
.reviews[index].rating .productDetailService[0].reviews[index].rating
.toDouble(), .toDouble(),
size: 15.0, size: 15.0,
filledColor: Colors.yellow[700], filledColor: Colors.yellow[700],
@ -63,8 +64,8 @@ class ReviewsInfo extends StatelessWidget {
), ),
Container( Container(
child: Text( child: Text(
previousModel.productDetailService[0].reviews[index] previousModel
.reviewText, .productDetailService[0].reviews[index].reviewText,
style: TextStyle(fontSize: 20), style: TextStyle(fontSize: 20),
), ),
), ),

@ -17,12 +17,14 @@ class IconWithBg extends StatelessWidget {
color: Colors.grey[200], color: Colors.grey[200],
borderRadius: BorderRadius.circular(30), borderRadius: BorderRadius.circular(30),
), ),
child: Center(
child: IconButton( child: IconButton(
icon: Icon(icon), icon: Icon(icon, size: 20,),
color: color, color: color,
onPressed: () async { onPressed: () async {
onPress(); onPress();
}, },
),
)); ));
} }
} }

@ -18,9 +18,18 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
final ProductDetailViewModel model; final ProductDetailViewModel model;
final Function addToWishlistFunction; final Function addToWishlistFunction;
final Function deleteFromWishlistFunction;
final int quantity; final int quantity;
final bool isInWishList;
ProductAppBar({Key key, this.product, this.model, this.addToWishlistFunction, this.quantity}) ProductAppBar(
{Key key,
this.product,
this.model,
this.addToWishlistFunction,
this.quantity,
this.deleteFromWishlistFunction,
this.isInWishList})
: super(key: key); : super(key: key);
AuthenticatedUserObject authenticatedUserObject = AuthenticatedUserObject authenticatedUserObject =
@ -43,7 +52,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
Row( Row(
children: [ children: [
IconWithBg( IconWithBg(
icon: Icons.arrow_back_ios, icon: Icons.arrow_back,
color: Colors.grey, color: Colors.grey,
onPress: () { onPress: () {
Navigator.pop(context); Navigator.pop(context);
@ -56,7 +65,7 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
children: [ children: [
IconWithBg( IconWithBg(
icon: Icons.shopping_cart, icon: Icons.shopping_cart,
color: Colors.grey, color: Colors.grey[800],
onPress: () { onPress: () {
Navigator.push( Navigator.push(
context, context,
@ -84,7 +93,6 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
); );
} }
@override
@override @override
Size get preferredSize => Size(double.maxFinite, 50); Size get preferredSize => Size(double.maxFinite, 50);
@ -101,37 +109,48 @@ class ProductAppBar extends StatelessWidget with PreferredSizeWidget {
title: Text( title: Text(
TranslationBase.of(context).addToCart, TranslationBase.of(context).addToCart,
), ),
onTap: () => { onTap: () async {
if (quantity > 0) if (quantity > 0) {
{ {
addToCartFunction( await addToCartFunction(
quantity: quantity, quantity: quantity,
itemID: itemID, itemID: itemID,
context: context, context: context,
model: model) model: model);
Navigator.of(context).pop();
} }
else } else {
{
AppToast.showErrorToast( AppToast.showErrorToast(
message: "you should add quantity") message: "you should add quantity");
} }
}), }),
ListTile( ListTile(
leading: Icon(Icons.favorite_border), leading: Icon(
title: Text( !isInWishList ? Icons.favorite_border : Icons.favorite,
TranslationBase.of(context).addToWishlist, color: !isInWishList ? Colors.white : Colors.red[800],
), ),
onTap: () => title: Text(
{addToWishlistFunction(itemID: itemID, model: model)}, isInWishList
? TranslationBase.of(context).removeFromWishlist
: TranslationBase.of(context).addToWishlist,
), ),
onTap: () async {
if (isInWishList)
await deleteFromWishlistFunction();
else
await addToWishlistFunction();
Navigator.of(context).pop();
}),
ListTile( ListTile(
leading: Icon(Icons.compare), leading: Icon(Icons.compare),
title: Text( title: Text(
TranslationBase.of(context).compare, TranslationBase.of(context).compare,
), ),
onTap: () => { onTap: () {
Provider.of<CompareList>(context, listen: false) Provider.of<CompareList>(context, listen: false)
.addItem(specificationData), .addItem(specificationData);
Navigator.of(context).pop();
}, },
), ),
], ],

@ -7,6 +7,7 @@ import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/models/pharmacy/specification.dart'; import 'package:diplomaticquarterapp/models/pharmacy/specification.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
class ProductDetailService extends BaseService { class ProductDetailService extends BaseService {
bool isLogin = false; bool isLogin = false;
@ -98,7 +99,7 @@ class ProductDetailService extends BaseService {
}, onFailure: (String error, int statusCode) { }, onFailure: (String error, int statusCode) {
hasError = true; hasError = true;
super.error = error; super.error = error;
AppToast.showErrorToast(message: super.error??'something went wrong please try again'); AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage());
}, body: request); }, body: request);
} }
@ -109,7 +110,7 @@ class ProductDetailService extends BaseService {
}, onFailure: (String error, int statusCode) { }, onFailure: (String error, int statusCode) {
hasError = true; hasError = true;
super.error = error; 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(); _wishListProducts.clear();
response['shopping_carts'].forEach((item) { response['shopping_carts'].forEach((item) {
_wishListProducts.add(Wishlist.fromJson(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) { }, onFailure: (String error, int statusCode) {
hasError = true; hasError = true;
super.error = error; super.error = error;
AppToast.showErrorToast(message: 'something went wrong please try again'); AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage());
}, body: request); }, body: request);
} }
@ -149,7 +151,7 @@ class ProductDetailService extends BaseService {
super.error = error; super.error = error;
}); });
} }
Future delteItemFromWishlist(itemID) async { Future deleteItemFromWishlist(itemID) async {
var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID);
hasError = false; hasError = false;
await baseAppClient.getPharmacy(DELETE_WISHLIST+customerId+"+&product_id="+itemID+"&cart_type=Wishlist", await baseAppClient.getPharmacy(DELETE_WISHLIST+customerId+"+&product_id="+itemID+"&cart_type=Wishlist",

@ -1398,6 +1398,8 @@ class TranslationBase {
String get addToCart => localizedValues['addToCart'][locale.languageCode]; String get addToCart => localizedValues['addToCart'][locale.languageCode];
String get addToWishlist => String get addToWishlist =>
localizedValues['addToWishlist'][locale.languageCode]; localizedValues['addToWishlist'][locale.languageCode];
String get removeFromWishlist =>
localizedValues['removeFromWishlist'][locale.languageCode];
String get buyNow => localizedValues['buyNow'][locale.languageCode]; String get buyNow => localizedValues['buyNow'][locale.languageCode];
String get quantityShortcut => String get quantityShortcut =>
localizedValues['quantityShortcut'][locale.languageCode]; localizedValues['quantityShortcut'][locale.languageCode];

Loading…
Cancel
Save