Merge branch 'haroon-new-design' into 'development_new_design_2.0'

Product detail page updates

See merge request Cloud_Solution/diplomatic-quarter!495
merge-requests/496/merge
haroon amjad 3 years ago
commit 9563998fc3

@ -1,16 +1,15 @@
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/pharmacyModule/OrderPreviewViewModel.dart';
import 'package:diplomaticquarterapp/models/pharmacy/Wishlist.dart';
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/services/pharmacy_services/product_detail_service.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.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 '../../../locator.dart';
@ -28,6 +27,11 @@ class ProductDetailViewModel extends BaseViewModel{
bool hasError = false;
num get stockQuantity => _productDetailService.stockQuantity;
String get stockAvailability => _productDetailService.stockAvailability;
bool get isStockAvailable => _productDetailService.isStockAvailable;
Future getProductReviewsData(productID) async {
hasError = false;
@ -72,8 +76,7 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.ErrorLocal);
} else {
setState(ViewState.Idle);
Provider.of<OrderPreviewViewModel>(locator<NavigationService>().navigatorKey.currentContext, listen: false)
.setShoppingCartResponse( object);
Provider.of<OrderPreviewViewModel>(locator<NavigationService>().navigatorKey.currentContext, listen: false).setShoppingCartResponse(object);
}
}
@ -103,11 +106,9 @@ class ProductDetailViewModel extends BaseViewModel{
Future addToWishlistData(itemID) async {
hasError = false;
setState(ViewState.BusyLocal);
GifLoaderDialogUtils.showMyDialog(
locator<NavigationService>().navigatorKey.currentContext);
GifLoaderDialogUtils.showMyDialog(locator<NavigationService>().navigatorKey.currentContext);
await _productDetailService.addToWishlist(itemID);
GifLoaderDialogUtils.hideDialog(
locator<NavigationService>().navigatorKey.currentContext);
GifLoaderDialogUtils.hideDialog(locator<NavigationService>().navigatorKey.currentContext);
if (_productDetailService.hasError) {
error = _productDetailService.error;
@ -127,15 +128,12 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.Idle);
}
Future deleteWishlistData(itemID) async {
hasError = false;
setState(ViewState.BusyLocal);
GifLoaderDialogUtils.showMyDialog(
locator<NavigationService>().navigatorKey.currentContext);
GifLoaderDialogUtils.showMyDialog(locator<NavigationService>().navigatorKey.currentContext);
await _productDetailService.deleteItemFromWishlist(itemID);
GifLoaderDialogUtils.hideDialog(
locator<NavigationService>().navigatorKey.currentContext);
GifLoaderDialogUtils.hideDialog(locator<NavigationService>().navigatorKey.currentContext);
if (_productDetailService.hasError) {
error = _productDetailService.error;
@ -144,7 +142,6 @@ class ProductDetailViewModel extends BaseViewModel{
setState(ViewState.Idle);
}
Future productSpecificationData(itemID) async {
hasError = false;
setState(ViewState.Busy);
@ -157,9 +154,6 @@ class ProductDetailViewModel extends BaseViewModel{
}
clearReview() {
productDetailService.clear();
}
}

@ -1,7 +1,3 @@
// To parse this JSON data, do
//
// final productDetail = productDetailFromJson(jsonString);
import 'dart:convert';
List<ProductDetail> productDetailFromJson(String str) => List<ProductDetail>.from(json.decode(str).map((x) => ProductDetail.fromJson(x)));
@ -230,9 +226,7 @@ class Customer {
enum Email { STEVE_GATES_NOP_COMMERCE_COM }
final emailValues = EnumValues({
"steve_gates@nopCommerce.com": Email.STEVE_GATES_NOP_COMMERCE_COM
});
final emailValues = EnumValues({"steve_gates@nopCommerce.com": Email.STEVE_GATES_NOP_COMMERCE_COM});
class EnumValues<T> {
Map<String, T> map;

@ -68,7 +68,7 @@ class _FooterWidgetState extends State<FooterWidget> {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Quantity",
TranslationBase.of(context).quantity,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
),
@ -157,7 +157,8 @@ class _FooterWidgetState extends State<FooterWidget> {
),
],
),
onPressed: () {
onPressed: widget.isAvailable && !widget.item.isRx
? () {
setState(() {
if (showUI) {
quantityUI = 80;
@ -167,7 +168,8 @@ class _FooterWidgetState extends State<FooterWidget> {
showUI = true;
}
});
},
}
: null,
),
),
SizedBox(
@ -207,20 +209,20 @@ class _FooterWidgetState extends State<FooterWidget> {
);
} else {
await widget.addToShoppingCartFunction(quantity: widget.quantity, itemID: widget.item.id, model: widget.model);
Navigator.of(context).pushNamed(
CART_ORDER_PAGE,
);
// Navigator.push(
// context,
// FadePage(page: CartOrderPage()),
// Navigator.of(context).pushNamed(
// CART_ORDER_PAGE,
// );
Navigator.push(
context,
FadePage(page: CartOrderPage()),
);
}
},
fontWeight: FontWeight.w600,
borderColor: Colors.grey[800],
borderRadius: 3,
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) {
return BaseView<ProductDetailViewModel>(
allowAny: true,
onModelReady: (model) {
model.getProductReviewsData(widget.product.id);
},
builder: (_, model, wi) => AppScaffold(
appBarTitle: TranslationBase.of(context).productDetails,
isShowAppBar: true,
@ -146,6 +149,7 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
notifyMeWhenAvailable(itemId: itemId, customerId: customerId, model: model);
},
isInWishList: isInWishList,
isStockAvailable: model.isStockAvailable,
),
),
SizedBox(
@ -302,10 +306,10 @@ class __ProductDetailPageState extends State<ProductDetailPage> {
),
),
bottomSheet: FooterWidget(
widget.product.stockAvailability != 'Out of stock',
model.isStockAvailable,
widget.product.orderMaximumQuantity,
widget.product.orderMinimumQuantity,
widget.product.stockQuantity,
model.stockQuantity,
widget.product,
quantity: quantity,
isOverQuantity: isOverQuantity,

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

@ -15,32 +15,49 @@ import 'package:diplomaticquarterapp/uitl/app_toast.dart';
class ProductDetailService extends BaseService {
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> get productDetailList => _productDetailList;
List<LocationModel> _productLocationList = List();
List<LocationModel> get productLocationList => _productLocationList;
List<Wishlist> _addToCartModel = List();
List<Wishlist> get addToCartModel => _addToCartModel;
List<Wishlist> _wishListProducts = List();
List<Wishlist> get wishListProducts => _wishListProducts;
List<SpecificationModel> _productSpecification = List();
List<SpecificationModel> get productSpecification => _productSpecification;
List<SpecificationModel> get productSpecification => _productSpecification;
Future getProductReviews(productID) async {
hasError = false;
await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL+productID+"?fields=reviews",
onSuccess: (dynamic response, int statusCode) {
await baseAppClient.getPharmacy(GET_PRODUCT_DETAIL + productID + "?fields=reviews,stock_quantity,stock_availability,IsStockAvailable", onSuccess: (dynamic response, int statusCode) {
_productDetailList.clear();
response['products'].forEach((item) {
_productDetailList.add(ProductDetail.fromJson(item));
print(response);
});
_stockQuantity = response['products'][0]['stock_quantity'];
_stockAvailability = response['products'][0]['stock_availability'];
_isStockAvailable = response['products'][0]['IsStockAvailable'];
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
@ -52,19 +69,18 @@ class ProductDetailService extends BaseService {
Map<String, dynamic> request;
request = {
"Channel": 3,
"DeviceTypeID": 2,
"IPAdress": "10.20.10.20",
"LanguageID": 2,
"PatientOutSA": 0,
"SKU": "6720020025",
"SessionID": null,
"VersionID": 5.6,
"generalid": "Cs2020@2016\$2958",
"isDentalAllowedBackend": false
// "Channel": 3,
// "DeviceTypeID": 2,
// "IPAdress": "10.20.10.20",
// "LanguageID": 2,
// "PatientOutSA": 0,
// "SKU": "6720020025",
// "SessionID": null,
// "VersionID": 5.6,
// "generalid": "Cs2020@2016\$2958",
// "isDentalAllowedBackend": false
};
await baseAppClient.post(GET_LOCATION,
onSuccess: (dynamic response, int statusCode) {
await baseAppClient.post(GET_LOCATION, onSuccess: (dynamic response, int statusCode) {
_productLocationList.clear();
response['PharmList'].forEach((item) {
_productLocationList.add(LocationModel.fromJson(item));
@ -83,19 +99,11 @@ class ProductDetailService extends BaseService {
Map<String, dynamic> request;
request = {
"shopping_cart_item":
{
"quantity": quantity,
"shopping_cart_type": "1",
"product_id": itemID,
"customer_id": customerId,
"language_id": 1
}
"shopping_cart_item": {"quantity": quantity, "shopping_cart_type": "1", "product_id": itemID, "customer_id": customerId, "language_id": 1}
};
dynamic localRes;
await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false,
onSuccess: (dynamic response, int statusCode) {
await baseAppClient.pharmacyPost(GET_SHOPPING_CART, isExternal: false, onSuccess: (dynamic response, int statusCode) {
_addToCartModel.clear();
response['shopping_carts'].forEach((item) {
_addToCartModel.add(Wishlist.fromJson(item));
@ -130,14 +138,12 @@ class ProductDetailService extends BaseService {
request = {
"shopping_cart_item": {"quantity": 1, "shopping_cart_type": "Wishlist", "product_id": itemID, "customer_id": customerId, "language_id": 1}
};
await baseAppClient.pharmacyPost(GET_SHOPPING_CART,
onSuccess: (dynamic response, int statusCode) {
await baseAppClient.pharmacyPost(GET_SHOPPING_CART, onSuccess: (dynamic response, int statusCode) {
_wishListProducts.clear();
response['shopping_carts'].forEach((item) {
_wishListProducts.add(Wishlist.fromJson(item));
});
AppToast.showSuccessToast(message: 'You have added a product to the Wishlist');
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
@ -148,8 +154,7 @@ class ProductDetailService extends BaseService {
Future getWishlistItems() async {
var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID);
hasError = false;
await baseAppClient.getPharmacy(GET_WISHLIST+customerId+"?shopping_cart_type=2",
onSuccess: (dynamic response, int statusCode) {
await baseAppClient.getPharmacy(GET_WISHLIST + customerId + "?shopping_cart_type=2", onSuccess: (dynamic response, int statusCode) {
_wishListProducts.clear();
response['shopping_carts'].forEach((item) {
_wishListProducts.add(Wishlist.fromJson(item));
@ -163,8 +168,7 @@ class ProductDetailService extends BaseService {
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",
onSuccess: (dynamic response, int statusCode) {
await baseAppClient.getPharmacy(DELETE_WISHLIST + customerId + "+&product_id=" + itemID + "&cart_type=Wishlist", onSuccess: (dynamic response, int statusCode) {
_wishListProducts.clear();
response['shopping_carts'].forEach((item) {
_wishListProducts.add(Wishlist.fromJson(item));
@ -180,8 +184,7 @@ class ProductDetailService extends BaseService {
Future productSpecificationData(itemID) async {
hasError = false;
await baseAppClient.getPharmacy(GET_SPECIFICATION+itemID,
onSuccess: (dynamic response, int statusCode) {
await baseAppClient.getPharmacy(GET_SPECIFICATION + itemID, onSuccess: (dynamic response, int statusCode) {
_productSpecification.clear();
response['specification'].forEach((item) {
_productSpecification.add(SpecificationModel.fromJson(item));
@ -192,5 +195,4 @@ class ProductDetailService extends BaseService {
super.error = error;
});
}
}

Loading…
Cancel
Save