offer update

This commit is contained in:
2025-02-09 02:13:44 +05:30
parent c6a6ded51d
commit 630a918307
22 changed files with 1027 additions and 986 deletions

View File

@@ -23,6 +23,28 @@ class BestDealScreen extends StatefulWidget {
}
class _BestDealScreenState extends State<BestDealScreen> {
@override
void initState() {
Provider.of<ProductProvider>(context, listen: false)
.getBestDealProduct(context);
super.initState();
}
int calculateDiscountPercentage(double basePrice, double discountPrice) {
print(
"Base Price (Before Discount): $basePrice, Discount Price (After Discount): $discountPrice");
if (basePrice <= 0 || discountPrice <= 0 || discountPrice > basePrice) {
print("Error: Invalid price values.");
return 0;
}
double discountAmount = basePrice - discountPrice;
double discountPercentage = (discountAmount / basePrice) * 100;
return discountPercentage.round();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -221,31 +243,24 @@ class _BestDealScreenState extends State<BestDealScreen> {
backGroundColor: Colors.transparent,
),
),
// Positioned(
// right: 5,
// top: 5,
// child: InkWell(
// onTap: () async {
// if (await SharedPrefUtils.getToken() !=
// null) {
// provider.toggleWishlist(
// context, bestdealproduct.id!);
// } else {
// context.push(MyRoutes.LOGIN);
// }
// },
// child: Icon(
// provider.wishlist
// .contains(bestdealproduct.id)
// ? Icons.favorite
// : Icons.favorite_border,
// color: provider.wishlist
// .contains(bestdealproduct.id)
// ? Colors.red
// : Colors.grey,
// ),
// ),
// ),
Positioned(
right: 1,
bottom: 0,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
"${calculateDiscountPercentage(double.parse(bestdealproduct.basePrice), double.parse(bestdealproduct.discountPrice))}% OFF",
style: TextStyle(
color: Colors.white, fontSize: 12)),
),
),
)
],
),
),