getOrder method
dynamic
getOrder(
- BuildContext context,
- OfferList offerList,
- String categoryName, {
- int scannedQty = 0,
Implementation
getOrder(
BuildContext context,
OfferList offerList,
String categoryName, {
int scannedQty = 0,
}) {
quantity.value = scannedQty;
quantityController.text = scannedQty.toString();
showModalBottomSheet<dynamic>(
isScrollControlled: true,
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return Container(
padding: EdgeInsets.only(
left: SizeConstant.getHeightWithScreen(15),
bottom: SizeConstant.getHeightWithScreen(15),
right: SizeConstant.getHeightWithScreen(15),
),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: ColorConstant.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(SizeConstant.getHeightWithScreen(30.0)),
topRight: Radius.circular(SizeConstant.getHeightWithScreen(30.0)),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Center(
child: Container(
height: SizeConstant.getHeightWithScreen(4),
width: SizeConstant.getHeightWithScreen(77),
color: ColorConstant.pgvDotColor,
margin: EdgeInsets.all(SizeConstant.getHeightWithScreen(6)),
),
),
Container(
height: SizeConstant.getHeightWithScreen(194),
padding: EdgeInsets.all(SizeConstant.getHeightWithScreen(15)),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: ColorConstant.white,
borderRadius: BorderRadius.all(
Radius.circular(
SizeConstant.getHeightWithScreen(26),
),
),
),
child: offerList.imageUrl == null
? SvgPicture.asset(
"assets/images/image_placeholder.svg",
package: "common",
height: SizeConstant.getHeightWithScreen(194),
width: SizeConstant.getHeightWithScreen(330),
fit: BoxFit.contain,
)
: Image(
image: NetworkImage(
"https://app.ventas.cellcard.com.kh${offerList.imageUrl}",
),
errorBuilder: (context, error, stackTrace) {
return SvgPicture.asset(
"assets/images/image_placeholder.svg",
package: Constants.packageName,
height: SizeConstant.getHeightWithScreen(194),
width: SizeConstant.getHeightWithScreen(330),
fit: BoxFit.contain,
);
},
height: SizeConstant.getHeightWithScreen(194),
width: SizeConstant.getHeightWithScreen(330),
fit: BoxFit.contain,
),
),
SizedBox(
height: SizeConstant.getHeightWithScreen(32),
),
Text(
offerList.offerName!,
textDirection: TextDirection.ltr,
style: TextStyle(
color: ColorConstant.black3,
fontSize: SizeConstant.xlargeFont,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: SizeConstant.getHeightWithScreen(7)),
Text(
"${Helper.amountWithCurrency(
stockOrderController.sellThruOrder.value.currency ?? "USD",
double.parse(offerList.price!.amount!),
)} / unit",
textDirection: TextDirection.ltr,
style: TextStyle(
color: ColorConstant.black3,
fontSize: SizeConstant.xxlargeFont,
fontWeight: FontWeight.w500,
),
),
SizedBox(height: SizeConstant.getHeightWithScreen(13)),
Text(
offerList.offerDescription == null
? ""
: offerList.offerDescription!,
style: TextStyle(
color: ColorConstant.grey5,
fontSize: SizeConstant.smallFont,
fontWeight: FontWeight.w400,
),
),
SizedBox(height: SizeConstant.getHeightWithScreen(30)),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
onTap: () {
if (quantity.value > 0) {
quantity.value -= 1;
}
quantityController.text = quantity.value.toString();
},
child: Obx(
() => Container(
height: SizeConstant.getHeightWithScreen(40),
width: SizeConstant.getHeightWithScreen(40),
decoration: BoxDecoration(
color: ColorConstant.dividerColor,
borderRadius: BorderRadius.circular(
SizeConstant.getHeightWithScreen(7),
),
),
padding: EdgeInsets.symmetric(
horizontal: SizeConstant.getHeightWithScreen(13),
),
child: SvgPicture.asset(
quantity.value == 0
? "assets/images/remove_disabled.svg"
: "assets/images/remove_enabled.svg",
package: Constants.packageName,
height: SizeConstant.getHeightWithScreen(2),
width: SizeConstant.getHeightWithScreen(14),
),
),
),
),
SizedBox(width: SizeConstant.getHeightWithScreen(5)),
VentasPrimaryTextField(
fillColor: ColorConstant.white,
borderColor: ColorConstant.pgvDotColor,
height: SizeConstant.getHeightWithScreen(40),
width: SizeConstant.getHeightWithScreen(65),
textInputType: TextInputType.number,
controller: quantityController,
hintText: "",
textAlignment: TextAlign.center,
onChanged: (p0) {
WidgetsBinding.instance.addPostFrameCallback((_) {
quantity.value = quantityController.text.isEmpty
? 0
: int.parse(quantityController.text);
});
},
contentPadding: EdgeInsets.symmetric(
vertical: SizeConstant.getHeightWithScreen(10),
),
),
SizedBox(width: SizeConstant.getHeightWithScreen(5)),
GestureDetector(
onTap: () {
quantity.value += 1;
quantityController.text = quantity.value.toString();
},
child: Container(
height: SizeConstant.getHeightWithScreen(40),
width: SizeConstant.getHeightWithScreen(40),
decoration: BoxDecoration(
color: ColorConstant.dividerColor,
borderRadius: BorderRadius.circular(
SizeConstant.getHeightWithScreen(7),
),
),
padding: EdgeInsets.symmetric(
horizontal: SizeConstant.getHeightWithScreen(13),
),
child: SvgPicture.asset(
"assets/images/add_enabled.svg",
package: Constants.packageName,
height: SizeConstant.getHeightWithScreen(14),
width: SizeConstant.getHeightWithScreen(14),
),
),
),
SizedBox(width: SizeConstant.getHeightWithScreen(20)),
Obx(() {
return Expanded(
child: VentasPrimaryButton(
onTap: quantity.value == 0 && scannedQty == 0
? null
: () {
if (quantity.value > 0) {
int difference = quantity.value - scannedQty;
int positiveDifference = difference.abs();
if (scannedQty == 0) {
stockOrderController.quantity.value =
quantity.value;
AddToCartRequest request =
prepareCartRequest(
offerList.pogId,
offerList.offerId,
'$positiveDifference',
);
Navigator.of(context).pop();
var product = ProductContentModel(
productName: offerList.offerName,
itemAmount: double.parse(
offerList.price!.amount!),
scannedQty: quantity.value);
if (stockOrderController
.cart_id.value.isEmpty) {
stockOrderController.addToCart(
context, request, product);
} else {
stockOrderController.updateCart(
context,
stockOrderController.cart_id.value,
request,
product,
isShowMsg: true,
);
}
} else {
String productId = stockOrderController
.getProductId(offerList.offerId);
Navigator.of(context).pop();
if (productId.isNotEmpty) {
stockOrderController.updateQuantity(
context,
(quantity).toString(),
stockOrderController.cart_id.toString(),
productId,
);
} else {
print('productId is empty');
}
}
} else {
String productId = stockOrderController
.getProductId(offerList.offerId);
Navigator.of(context).pop();
if (productId.isNotEmpty) {
stockOrderController.deleteProduct(
context,
stockOrderController.cart_id.toString(),
productId,
);
} else {
print('productId is empty');
}
}
},
label: localization.translate('add'),
btnHeight: SizeConstant.getHeightWithScreen(40),
// btnWidth: SizeConstant.getHeightWithScreen(155),
textColor: quantity.value == 0 && scannedQty == 0
? ColorConstant.tfHintTextColor
: ColorConstant.white,
borderRadius: SizeConstant.getHeightWithScreen(7),
bgColor: quantity.value == 0 && scannedQty == 0
? ColorConstant.pgvActiveDotColor
: ColorConstant.primaryColor,
borderColor: quantity.value == 0 && scannedQty == 0
? ColorConstant.pgvActiveDotColor
: ColorConstant.primaryColor,
),
);
}),
],
),
SizedBox(
height: MediaQuery.of(context).viewInsets.bottom,
),
],
),
);
},
);
}