Product detail page updates

merge-update-with-lab-changes
haroon amjad 4 years ago
parent 75989bdc01
commit 6ffa07392c

@ -1,21 +1,20 @@
import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart'; import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart';
import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart'; import 'package:diplomaticquarterapp/models/pharmacy/locationModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/productDetailModel.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/models/pharmacy/specification.dart';
import 'package:diplomaticquarterapp/services/pharmacy_services/product_detail_service.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/navigation_service.dart'; import 'package:diplomaticquarterapp/uitl/navigation_service.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCart.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ShoppingCartResponse.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../../../locator.dart'; import '../../../locator.dart';
class ProductDetailViewModel extends BaseViewModel{ class ProductDetailViewModel extends BaseViewModel {
ProductDetailService _productDetailService = locator<ProductDetailService>(); ProductDetailService _productDetailService = locator<ProductDetailService>();
List<ProductDetail> get productDetailService => _productDetailService.productDetailList; List<ProductDetail> get productDetailService => _productDetailService.productDetailList;
@ -28,6 +27,11 @@ class ProductDetailViewModel extends BaseViewModel{
bool hasError = false; bool hasError = false;
num get stockQuantity => _productDetailService.stockQuantity;
String get stockAvailability => _productDetailService.stockAvailability;
bool get isStockAvailable => _productDetailService.isStockAvailable;
Future getProductReviewsData(productID) async { Future getProductReviewsData(productID) async {
hasError = false; hasError = false;
@ -72,8 +76,7 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.ErrorLocal); setState(ViewState.ErrorLocal);
} else { } else {
setState(ViewState.Idle); setState(ViewState.Idle);
Provider.of<OrderPreviewViewModel>(locator<NavigationService>().navigatorKey.currentContext, listen: false) Provider.of<OrderPreviewViewModel>(locator<NavigationService>().navigatorKey.currentContext, listen: false).setShoppingCartResponse(object);
.setShoppingCartResponse( object);
} }
} }
@ -103,11 +106,9 @@ class ProductDetailViewModel extends BaseViewModel{
Future addToWishlistData(itemID) async { Future addToWishlistData(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.addToWishlist(itemID); await _productDetailService.addToWishlist(itemID);
GifLoaderDialogUtils.hideDialog( GifLoaderDialogUtils.hideDialog(locator<NavigationService>().navigatorKey.currentContext);
locator<NavigationService>().navigatorKey.currentContext);
if (_productDetailService.hasError) { if (_productDetailService.hasError) {
error = _productDetailService.error; error = _productDetailService.error;
@ -127,15 +128,12 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.Idle); setState(ViewState.Idle);
} }
Future deleteWishlistData(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.deleteItemFromWishlist(itemID); await _productDetailService.deleteItemFromWishlist(itemID);
GifLoaderDialogUtils.hideDialog( GifLoaderDialogUtils.hideDialog(locator<NavigationService>().navigatorKey.currentContext);
locator<NavigationService>().navigatorKey.currentContext);
if (_productDetailService.hasError) { if (_productDetailService.hasError) {
error = _productDetailService.error; error = _productDetailService.error;
@ -144,7 +142,6 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.Idle); setState(ViewState.Idle);
} }
Future productSpecificationData(itemID) async { Future productSpecificationData(itemID) async {
hasError = false; hasError = false;
setState(ViewState.Busy); setState(ViewState.Busy);
@ -156,10 +153,7 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.Idle); setState(ViewState.Idle);
} }
clearReview(){ clearReview() {
productDetailService.clear(); productDetailService.clear();
} }
}
}

@ -1,7 +1,3 @@
// To parse this JSON data, do
//
// final productDetail = productDetailFromJson(jsonString);
import 'dart:convert'; import 'dart:convert';
List<ProductDetail> productDetailFromJson(String str) => List<ProductDetail>.from(json.decode(str).map((x) => ProductDetail.fromJson(x))); List<ProductDetail> productDetailFromJson(String str) => List<ProductDetail>.from(json.decode(str).map((x) => ProductDetail.fromJson(x)));
@ -16,12 +12,12 @@ class ProductDetail {
List<Review> reviews; List<Review> reviews;
factory ProductDetail.fromJson(Map<String, dynamic> json) => ProductDetail( factory ProductDetail.fromJson(Map<String, dynamic> json) => ProductDetail(
reviews: List<Review>.from(json["reviews"].map((x) => Review.fromJson(x))), reviews: List<Review>.from(json["reviews"].map((x) => Review.fromJson(x))),
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"reviews": List<dynamic>.from(reviews.map((x) => x.toJson())), "reviews": List<dynamic>.from(reviews.map((x) => x.toJson())),
}; };
} }
class Review { class Review {
@ -62,42 +58,42 @@ class Review {
dynamic product; dynamic product;
factory Review.fromJson(Map<String, dynamic> json) => Review( factory Review.fromJson(Map<String, dynamic> json) => Review(
id: json["id"], id: json["id"],
position: json["position"], position: json["position"],
reviewId: json["review_id"], reviewId: json["review_id"],
customerId: json["customer_id"], customerId: json["customer_id"],
productId: json["product_id"], productId: json["product_id"],
storeId: json["store_id"], storeId: json["store_id"],
isApproved: json["is_approved"], isApproved: json["is_approved"],
title: json["title"], title: json["title"],
reviewText: json["review_text"], reviewText: json["review_text"],
replyText: json["reply_text"], replyText: json["reply_text"],
rating: json["rating"], rating: json["rating"],
helpfulYesTotal: json["helpful_yes_total"], helpfulYesTotal: json["helpful_yes_total"],
helpfulNoTotal: json["helpful_no_total"], helpfulNoTotal: json["helpful_no_total"],
createdOnUtc: DateTime.parse(json["created_on_utc"]), createdOnUtc: DateTime.parse(json["created_on_utc"]),
customer: Customer.fromJson(json["customer"]), customer: Customer.fromJson(json["customer"]),
product: json["product"], product: json["product"],
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"id": id, "id": id,
"position": position, "position": position,
"review_id": reviewId, "review_id": reviewId,
"customer_id": customerId, "customer_id": customerId,
"product_id": productId, "product_id": productId,
"store_id": storeId, "store_id": storeId,
"is_approved": isApproved, "is_approved": isApproved,
"title": title, "title": title,
"review_text": reviewText, "review_text": reviewText,
"reply_text": replyText, "reply_text": replyText,
"rating": rating, "rating": rating,
"helpful_yes_total": helpfulYesTotal, "helpful_yes_total": helpfulYesTotal,
"helpful_no_total": helpfulNoTotal, "helpful_no_total": helpfulNoTotal,
"created_on_utc": createdOnUtc.toIso8601String(), "created_on_utc": createdOnUtc.toIso8601String(),
"customer": customer.toJson(), "customer": customer.toJson(),
"product": product, "product": product,
}; };
} }
class Customer { class Customer {
@ -164,75 +160,73 @@ class Customer {
dynamic registeredInStoreId; dynamic registeredInStoreId;
factory Customer.fromJson(Map<String, dynamic> json) => Customer( factory Customer.fromJson(Map<String, dynamic> json) => Customer(
fileNumber: json["file_number"], fileNumber: json["file_number"],
iqamaNumber: json["iqama_number"], iqamaNumber: json["iqama_number"],
isOutSa: json["is_out_sa"], isOutSa: json["is_out_sa"],
patientType: json["patient_type"], patientType: json["patient_type"],
gender: json["gender"], gender: json["gender"],
birthDate: DateTime.parse(json["birth_date"]), birthDate: DateTime.parse(json["birth_date"]),
phone: json["phone"], phone: json["phone"],
countryCode: json["country_code"], countryCode: json["country_code"],
yahalaAccountno: json["yahala_accountno"], yahalaAccountno: json["yahala_accountno"],
billingAddress: json["billing_address"], billingAddress: json["billing_address"],
shippingAddress: json["shipping_address"], shippingAddress: json["shipping_address"],
id: json["id"], id: json["id"],
username: emailValues.map[json["username"]], username: emailValues.map[json["username"]],
email: emailValues.map[json["email"]], email: emailValues.map[json["email"]],
firstName: json["first_name"], firstName: json["first_name"],
lastName: json["last_name"], lastName: json["last_name"],
languageId: json["language_id"], languageId: json["language_id"],
adminComment: json["admin_comment"], adminComment: json["admin_comment"],
isTaxExempt: json["is_tax_exempt"], isTaxExempt: json["is_tax_exempt"],
hasShoppingCartItems: json["has_shopping_cart_items"], hasShoppingCartItems: json["has_shopping_cart_items"],
active: json["active"], active: json["active"],
deleted: json["deleted"], deleted: json["deleted"],
isSystemAccount: json["is_system_account"], isSystemAccount: json["is_system_account"],
systemName: json["system_name"], systemName: json["system_name"],
lastIpAddress: json["last_ip_address"], lastIpAddress: json["last_ip_address"],
createdOnUtc: json["created_on_utc"], createdOnUtc: json["created_on_utc"],
lastLoginDateUtc: json["last_login_date_utc"], lastLoginDateUtc: json["last_login_date_utc"],
lastActivityDateUtc: json["last_activity_date_utc"], lastActivityDateUtc: json["last_activity_date_utc"],
registeredInStoreId: json["registered_in_store_id"], registeredInStoreId: json["registered_in_store_id"],
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"file_number": fileNumber, "file_number": fileNumber,
"iqama_number": iqamaNumber, "iqama_number": iqamaNumber,
"is_out_sa": isOutSa, "is_out_sa": isOutSa,
"patient_type": patientType, "patient_type": patientType,
"gender": gender, "gender": gender,
"birth_date": birthDate.toIso8601String(), "birth_date": birthDate.toIso8601String(),
"phone": phone, "phone": phone,
"country_code": countryCode, "country_code": countryCode,
"yahala_accountno": yahalaAccountno, "yahala_accountno": yahalaAccountno,
"billing_address": billingAddress, "billing_address": billingAddress,
"shipping_address": shippingAddress, "shipping_address": shippingAddress,
"id": id, "id": id,
"username": emailValues.reverse[username], "username": emailValues.reverse[username],
"email": emailValues.reverse[email], "email": emailValues.reverse[email],
"first_name": firstName, "first_name": firstName,
"last_name": lastName, "last_name": lastName,
"language_id": languageId, "language_id": languageId,
"admin_comment": adminComment, "admin_comment": adminComment,
"is_tax_exempt": isTaxExempt, "is_tax_exempt": isTaxExempt,
"has_shopping_cart_items": hasShoppingCartItems, "has_shopping_cart_items": hasShoppingCartItems,
"active": active, "active": active,
"deleted": deleted, "deleted": deleted,
"is_system_account": isSystemAccount, "is_system_account": isSystemAccount,
"system_name": systemName, "system_name": systemName,
"last_ip_address": lastIpAddress, "last_ip_address": lastIpAddress,
"created_on_utc": createdOnUtc, "created_on_utc": createdOnUtc,
"last_login_date_utc": lastLoginDateUtc, "last_login_date_utc": lastLoginDateUtc,
"last_activity_date_utc": lastActivityDateUtc, "last_activity_date_utc": lastActivityDateUtc,
"registered_in_store_id": registeredInStoreId, "registered_in_store_id": registeredInStoreId,
}; };
} }
enum Email { STEVE_GATES_NOP_COMMERCE_COM } enum Email { STEVE_GATES_NOP_COMMERCE_COM }
final emailValues = EnumValues({ final emailValues = EnumValues({"steve_gates@nopCommerce.com": Email.STEVE_GATES_NOP_COMMERCE_COM});
"steve_gates@nopCommerce.com": Email.STEVE_GATES_NOP_COMMERCE_COM
});
class EnumValues<T> { class EnumValues<T> {
Map<String, T> map; Map<String, T> map;

@ -68,7 +68,7 @@ class _FooterWidgetState extends State<FooterWidget> {
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Text( child: Text(
"Quantity", TranslationBase.of(context).quantity,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold), style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
), ),
), ),
@ -157,17 +157,19 @@ class _FooterWidgetState extends State<FooterWidget> {
), ),
], ],
), ),
onPressed: () { onPressed: widget.isAvailable && !widget.item.isRx
setState(() { ? () {
if (showUI) { setState(() {
quantityUI = 80; if (showUI) {
showUI = false; quantityUI = 80;
} else { showUI = false;
quantityUI = 160; } else {
showUI = true; quantityUI = 160;
} showUI = true;
}); }
}, });
}
: null,
), ),
), ),
SizedBox( SizedBox(
@ -207,20 +209,20 @@ class _FooterWidgetState extends State<FooterWidget> {
); );
} else { } else {
await widget.addToShoppingCartFunction(quantity: widget.quantity, itemID: widget.item.id, model: widget.model); await widget.addToShoppingCartFunction(quantity: widget.quantity, itemID: widget.item.id, model: widget.model);
Navigator.of(context).pushNamed( // Navigator.of(context).pushNamed(
CART_ORDER_PAGE, // CART_ORDER_PAGE,
);
// Navigator.push(
// context,
// FadePage(page: CartOrderPage()),
// ); // );
Navigator.push(
context,
FadePage(page: CartOrderPage()),
);
} }
}, },
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
borderColor: Colors.grey[800], borderColor: Colors.grey[800],
borderRadius: 3, borderRadius: 3,
disableColor: Colors.grey[700], disableColor: Colors.grey[700],
color: !widget.isAvailable && widget.quantity > 0 || widget.quantity > widget.quantityLimit || widget.item.rxMessage != null ? Colors.grey : Colors.grey[800], color: !widget.isAvailable && widget.quantity > 0 || widget.quantity > widget.quantityLimit || widget.item.isRx ? Colors.grey : Colors.grey[800],
), ),
), ),
], ],

@ -87,6 +87,9 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BaseView<ProductDetailViewModel>( return BaseView<ProductDetailViewModel>(
allowAny: true, allowAny: true,
onModelReady: (model) {
model.getProductReviewsData(widget.product.id);
},
builder: (_, model, wi) => AppScaffold( builder: (_, model, wi) => AppScaffold(
appBarTitle: TranslationBase.of(context).productDetails, appBarTitle: TranslationBase.of(context).productDetails,
isShowAppBar: true, isShowAppBar: true,
@ -146,6 +149,7 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
notifyMeWhenAvailable(itemId: itemId, customerId: customerId, model: model); notifyMeWhenAvailable(itemId: itemId, customerId: customerId, model: model);
}, },
isInWishList: isInWishList, isInWishList: isInWishList,
isStockAvailable: model.isStockAvailable,
), ),
), ),
SizedBox( SizedBox(
@ -302,10 +306,10 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
), ),
), ),
bottomSheet: FooterWidget( bottomSheet: FooterWidget(
widget.product.stockAvailability != 'Out of stock', model.isStockAvailable,
widget.product.orderMaximumQuantity, widget.product.orderMaximumQuantity,
widget.product.orderMinimumQuantity, widget.product.orderMinimumQuantity,
widget.product.stockQuantity, model.stockQuantity,
widget.product, widget.product,
quantity: quantity, quantity: quantity,
isOverQuantity: isOverQuantity, isOverQuantity: isOverQuantity,

@ -1,7 +1,6 @@
import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart'; import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.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'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -20,16 +19,12 @@ class ProductNameAndPrice extends StatefulWidget {
final Function notifyMeWhenAvailable; final Function notifyMeWhenAvailable;
final Function addToWishlistFunction; final Function addToWishlistFunction;
final Function deleteFromWishlistFunction; final Function deleteFromWishlistFunction;
final bool isStockAvailable;
AuthenticatedUserObject authenticatedUserObject = AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
locator<AuthenticatedUserObject>();
ProductNameAndPrice(this.context, this.item, ProductNameAndPrice(this.context, this.item,
{this.customerId, {this.customerId, this.isInWishList, this.notifyMeWhenAvailable, this.addToWishlistFunction, this.deleteFromWishlistFunction, @required this.isStockAvailable});
this.isInWishList,
this.notifyMeWhenAvailable,
this.addToWishlistFunction,
this.deleteFromWishlistFunction});
@override @override
_ProductNameAndPriceState createState() => _ProductNameAndPriceState(); _ProductNameAndPriceState createState() => _ProductNameAndPriceState();
@ -51,25 +46,18 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Texts(widget.item.price.toString() + " " + "SR", Texts(widget.item.price.toString() + " " + TranslationBase.of(context).sar, fontWeight: FontWeight.bold, fontSize: 20),
fontWeight: FontWeight.bold, fontSize: 20),
Texts( Texts(
projectViewModel.isArabic projectViewModel.isArabic ? widget.item.stockAvailabilityn : widget.item.stockAvailability,
? widget.item.stockAvailabilityn
: widget.item.stockAvailability,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 15, fontSize: 15,
color: widget.item.stockAvailability == 'Out of stock' color: widget.isStockAvailable ? Colors.green : Colors.red,
? Colors.red
: Colors.green,
), ),
// SizedBox(width: 20), // SizedBox(width: 20),
if (widget.authenticatedUserObject.isLogin) if (widget.authenticatedUserObject.isLogin)
widget.item.stockAvailability == 'Out of stock' && widget.isStockAvailable && widget.customerId != null
widget.customerId != null
? InkWell( ? InkWell(
onTap: () => widget.notifyMeWhenAvailable( onTap: () => 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,
@ -85,23 +73,15 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
]), ]),
) )
: IconWithBg( : IconWithBg(
icon: !widget.isInWishList icon: !widget.isInWishList ? Icons.favorite_border : Icons.favorite,
? Icons.favorite_border color: !widget.isInWishList ? Colors.white : Colors.red[800],
: Icons.favorite,
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.addToWishlistFunction(widget.item.id);
await widget
.addToWishlistFunction(widget.item.id);
} else { } else {
await widget await widget.deleteFromWishlistFunction(widget.item.id);
.deleteFromWishlistFunction(widget.item.id);
} }
} else { } else {
return; return;
@ -118,13 +98,9 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
child: Container( child: Container(
margin: EdgeInsets.only(left: 5), margin: EdgeInsets.only(left: 5),
child: Align( child: Align(
alignment: projectViewModel.isArabic alignment: projectViewModel.isArabic ? Alignment.topRight : Alignment.topLeft,
? Alignment.topRight
: Alignment.topLeft,
child: Text( child: Text(
projectViewModel.isArabic projectViewModel.isArabic ? widget.item.namen : widget.item.name,
? widget.item.namen
: widget.item.name,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
), ),
), ),
@ -140,8 +116,7 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
child: Row( child: Row(
children: [ children: [
RatingBar.readOnly( RatingBar.readOnly(
initialRating: double.parse( initialRating: double.parse(widget.item.approvedRatingSum.toString()),
widget.item.approvedRatingSum.toString()),
size: 15.0, size: 15.0,
filledColor: Colors.yellow[700], filledColor: Colors.yellow[700],
emptyColor: Colors.grey[400], emptyColor: Colors.grey[400],
@ -172,19 +147,9 @@ class _ProductNameAndPriceState extends State<ProductNameAndPrice> {
Row( Row(
children: [ children: [
Text( Text(
projectViewModel.isArabic projectViewModel.isArabic ? widget.item.rxMessagen.toString() : widget.item.rxMessage.toString(),
? widget.item.rxMessagen.toString()
: widget.item.rxMessage.toString(),
style: TextStyle(color: Colors.red, fontSize: 10), style: TextStyle(color: Colors.red, fontSize: 10),
), ),
SizedBox(
width: 5,
),
Icon(
FontAwesomeIcons.questionCircle,
color: Colors.red,
size: 15.0,
)
], ],
) )
], ],

@ -15,36 +15,53 @@ import 'package:diplomaticquarterapp/uitl/app_toast.dart';
class ProductDetailService extends BaseService { class ProductDetailService extends BaseService {
bool isLogin = false; bool isLogin = false;
num _stockQuantity;
num get stockQuantity => _stockQuantity;
String _stockAvailability;
String get stockAvailability => _stockAvailability;
bool _isStockAvailable;
bool get isStockAvailable => _isStockAvailable;
List<ProductDetail> _productDetailList = List(); List<ProductDetail> _productDetailList = List();
List<ProductDetail> get productDetailList => _productDetailList; List<ProductDetail> get productDetailList => _productDetailList;
List<LocationModel> _productLocationList = List(); List<LocationModel> _productLocationList = List();
List<LocationModel> get productLocationList => _productLocationList; List<LocationModel> get productLocationList => _productLocationList;
List<Wishlist> _addToCartModel = List(); List<Wishlist> _addToCartModel = List();
List<Wishlist> get addToCartModel => _addToCartModel; List<Wishlist> get addToCartModel => _addToCartModel;
List<Wishlist> _wishListProducts = List(); List<Wishlist> _wishListProducts = List();
List<Wishlist> get wishListProducts => _wishListProducts; List<Wishlist> get wishListProducts => _wishListProducts;
List<SpecificationModel> _productSpecification = List(); List<SpecificationModel> _productSpecification = List();
List<SpecificationModel> get productSpecification => _productSpecification;
List<SpecificationModel> get productSpecification => _productSpecification;
Future getProductReviews(productID) async { Future getProductReviews(productID) async {
hasError = false; hasError = false;
await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL+productID+"?fields=reviews", await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL + productID + "?fields=reviews,stock_quantity,stock_availability,IsStockAvailable", onSuccess: (dynamic response, int statusCode) {
onSuccess: (dynamic response, int statusCode) { _productDetailList.clear();
_productDetailList.clear(); response['products'].forEach((item) {
response['products'].forEach((item) { _productDetailList.add(ProductDetail.fromJson(item));
_productDetailList.add(ProductDetail.fromJson(item)); print(response);
print(response); });
}); _stockQuantity = response['products'][0]['stock_quantity'];
}, onFailure: (String error, int statusCode) { _stockAvailability = response['products'][0]['stock_availability'];
hasError = true; _isStockAvailable = response['products'][0]['IsStockAvailable'];
super.error = error; }, onFailure: (String error, int statusCode) {
}); hasError = true;
super.error = error;
});
} }
Future getProductAvailabiltyDetail() async { Future getProductAvailabiltyDetail() async {
@ -52,29 +69,28 @@ class ProductDetailService extends BaseService {
Map<String, dynamic> request; Map<String, dynamic> request;
request = { request = {
"Channel": 3, // "Channel": 3,
"DeviceTypeID": 2, // "DeviceTypeID": 2,
"IPAdress": "10.20.10.20", // "IPAdress": "10.20.10.20",
"LanguageID": 2, // "LanguageID": 2,
"PatientOutSA": 0, // "PatientOutSA": 0,
"SKU": "6720020025", // "SKU": "6720020025",
"SessionID": null, // "SessionID": null,
"VersionID": 5.6, // "VersionID": 5.6,
"generalid": "Cs2020@2016\$2958", // "generalid": "Cs2020@2016\$2958",
"isDentalAllowedBackend": false // "isDentalAllowedBackend": false
}; };
await baseAppClient.post(GET_LOCATION, await baseAppClient.post(GET_LOCATION, onSuccess: (dynamic response, int statusCode) {
onSuccess: (dynamic response, int statusCode) { _productLocationList.clear();
_productLocationList.clear(); response['PharmList'].forEach((item) {
response['PharmList'].forEach((item) { _productLocationList.add(LocationModel.fromJson(item));
_productLocationList.add(LocationModel.fromJson(item)); print(_productLocationList);
print(_productLocationList); print(response);
print(response); });
}); }, onFailure: (String error, int statusCode) {
}, onFailure: (String error, int statusCode) { hasError = true;
hasError = true; super.error = error;
super.error = error; }, body: request);
}, body: request);
} }
Future<Map> addToCart(quantity, itemID) async { Future<Map> addToCart(quantity, itemID) async {
@ -83,30 +99,22 @@ class ProductDetailService extends BaseService {
Map<String, dynamic> request; Map<String, dynamic> request;
request = { request = {
"shopping_cart_item": "shopping_cart_item": {"quantity": quantity, "shopping_cart_type": "1", "product_id": itemID, "customer_id": customerId, "language_id": 1}
{
"quantity": quantity,
"shopping_cart_type": "1",
"product_id": itemID,
"customer_id": customerId,
"language_id": 1
}
}; };
dynamic localRes; dynamic localRes;
await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false, await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false, onSuccess: (dynamic response, int statusCode) {
onSuccess: (dynamic response, int statusCode) { _addToCartModel.clear();
_addToCartModel.clear(); response['shopping_carts'].forEach((item) {
response['shopping_carts'].forEach((item) { _addToCartModel.add(Wishlist.fromJson(item));
_addToCartModel.add(Wishlist.fromJson(item)); });
}); AppToast.showSuccessToast(message: 'You have added a product to the cart');
AppToast.showSuccessToast(message: 'You have added a product to the cart'); localRes = response;
localRes = response; }, onFailure: (String error, int statusCode) {
}, onFailure: (String error, int statusCode) { hasError = true;
hasError = true; super.error = error;
super.error = error; AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage());
AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); }, body: request);
}, body: request);
return Future.value(localRes); return Future.value(localRes);
} }
@ -118,7 +126,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: error??Utils.generateContactAdminMessage()); AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage());
}); });
} }
@ -130,67 +138,61 @@ class ProductDetailService extends BaseService {
request = { request = {
"shopping_cart_item": {"quantity": 1, "shopping_cart_type": "Wishlist", "product_id": itemID, "customer_id": customerId, "language_id": 1} "shopping_cart_item": {"quantity": 1, "shopping_cart_type": "Wishlist", "product_id": itemID, "customer_id": customerId, "language_id": 1}
}; };
await baseAppClient.pharmacyPost(GET_SHOPPING_CART, await baseAppClient.pharmacyPost(GET_SHOPPING_CART, onSuccess: (dynamic response, int statusCode) {
onSuccess: (dynamic response, int statusCode) { _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) {
hasError = true;
}, onFailure: (String error, int statusCode) { super.error = error;
hasError = true; AppToast.showErrorToast(message: error ?? Utils.generateContactAdminMessage());
super.error = error; }, body: request);
AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage());
}, body: request);
} }
Future getWishlistItems() async { Future getWishlistItems() async {
var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID);
hasError = false; hasError = false;
await baseAppClient.getPharmacy(GET_WISHLIST+customerId+"?shopping_cart_type=2", await baseAppClient.getPharmacy(GET_WISHLIST + customerId + "?shopping_cart_type=2", onSuccess: (dynamic response, int statusCode) {
onSuccess: (dynamic response, int statusCode) { _wishListProducts.clear();
_wishListProducts.clear(); response['shopping_carts'].forEach((item) {
response['shopping_carts'].forEach((item) { _wishListProducts.add(Wishlist.fromJson(item));
_wishListProducts.add(Wishlist.fromJson(item)); });
}); }, onFailure: (String error, int statusCode) {
}, onFailure: (String error, int statusCode) { hasError = true;
hasError = true; super.error = error;
super.error = error; });
});
} }
Future deleteItemFromWishlist(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", onSuccess: (dynamic response, int statusCode) {
onSuccess: (dynamic response, int statusCode) { _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 removed a product from the Wishlist');
AppToast.showSuccessToast(message: 'You have removed a product from 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: error ?? Utils.generateContactAdminMessage());
AppToast.showErrorToast(message: error??Utils.generateContactAdminMessage()); });
});
} }
Future productSpecificationData(itemID) async { Future productSpecificationData(itemID) async {
hasError = false; hasError = false;
await baseAppClient.getPharmacy(GET_SPECIFICATION+itemID, await baseAppClient.getPharmacy(GET_SPECIFICATION + itemID, onSuccess: (dynamic response, int statusCode) {
onSuccess: (dynamic response, int statusCode) { _productSpecification.clear();
_productSpecification.clear(); response['specification'].forEach((item) {
response['specification'].forEach((item) { _productSpecification.add(SpecificationModel.fromJson(item));
_productSpecification.add(SpecificationModel.fromJson(item)); print(_productSpecification);
print(_productSpecification); });
}); }, onFailure: (String error, int statusCode) {
}, onFailure: (String error, int statusCode) { hasError = true;
hasError = true; super.error = error;
super.error = error; });
});
} }
} }

Loading…
Cancel
Save