addtowish

This commit is contained in:
bestonemitRam
2025-01-30 01:22:21 +05:30
parent cae6f13d35
commit 12056d7521
13 changed files with 957 additions and 778 deletions

View File

@@ -11,6 +11,7 @@ class APIURL {
static const String getBestDealProduct = "${BASE_URL}products/best-deals";
static const String getAllcategory = "${BASE_URL}categories";
static const String addToWish = "${BASE_URL}carts/wishlist/items";
static const String deleteToWish = "${BASE_URL}carts/wishlist/items";
static const String addToCart = "${BASE_URL}carts/items";
static const String gettAllWishList = "${BASE_URL}carts/wishlist";
static const String similarProduct = "${BASE_URL}products/";

View File

@@ -10,8 +10,7 @@ AllProductModel allProductModelFromJson(String str) =>
String allProductModelToJson(AllProductModel data) =>
json.encode(data.toJson());
class AllProductModel
{
class AllProductModel {
List<Product>? data;
Meta? meta;
@@ -33,69 +32,66 @@ class AllProductModel
}
class Product {
dynamic id;
dynamic name;
dynamic description;
dynamic additionalInfo;
dynamic id;
dynamic name;
dynamic description;
dynamic additionalInfo;
dynamic brand;
dynamic basePrice;
dynamic basePrice;
dynamic discountPrice;
dynamic stock;
dynamic quantity;
dynamic unit;
dynamic slug;
dynamic unit;
dynamic slug;
dynamic rating;
bool? isInStock;
bool? isActive;
DateTime? createdAt;
DateTime? updatedAt;
dynamic storeId;
dynamic categoryId;
dynamic storeId;
dynamic categoryId;
dynamic productTypeId;
dynamic timeSlotId;
Store? store;
Category? category;
dynamic productType;
dynamic timeSlot;
dynamic isInWishlist;
List<ProductImage>? productImages;
List<dynamic>? productTags;
List<dynamic>? zones;
List<ProductReview>? productReview;
Product({
this.id,
this.name,
this.description,
this.additionalInfo,
this.brand,
this.basePrice,
this.discountPrice,
this.stock,
this.quantity,
this.unit,
this.slug,
this.rating,
this.isInStock,
this.isActive,
this.createdAt,
this.updatedAt,
this.storeId,
this.categoryId,
this.productTypeId,
this.timeSlotId,
this.store,
this.category,
this.productType,
this.timeSlot,
this.productImages,
this.productTags,
this.zones,
this.productReview,
});
Product(
{this.id,
this.name,
this.description,
this.additionalInfo,
this.brand,
this.basePrice,
this.discountPrice,
this.stock,
this.quantity,
this.unit,
this.slug,
this.rating,
this.isInStock,
this.isActive,
this.createdAt,
this.updatedAt,
this.storeId,
this.categoryId,
this.productTypeId,
this.timeSlotId,
this.store,
this.category,
this.productType,
this.timeSlot,
this.productImages,
this.productTags,
this.zones,
this.productReview,
this.isInWishlist});
factory Product.fromJson(Map<String, dynamic> json) => Product(
id: json["id"],
@@ -128,6 +124,7 @@ class Product {
zones: List<dynamic>.from(json["zones"].map((x) => x)),
productReview: List<ProductReview>.from(
json["ProductReview"].map((x) => ProductReview.fromJson(x))),
isInWishlist: json["isInWishlist"],
);
Map<String, dynamic> toJson() => {
@@ -161,21 +158,23 @@ class Product {
"zones": List<dynamic>.from(zones!.map((x) => x)),
"ProductReview":
List<dynamic>.from(productReview!.map((x) => x.toJson())),
"isInWishlist": isInWishlist,
};
}
class Category {
dynamic id;
dynamic name;
dynamic description;
dynamic image;
dynamic slug;
dynamic id;
dynamic name;
dynamic description;
dynamic image;
dynamic slug;
dynamic level;
bool? isActive;
DateTime? createdAt;
DateTime? updatedAt;
dynamic parentCategoryId;
dynamic path;
dynamic path;
Category({
this.id,
@@ -221,10 +220,10 @@ class Category {
}
class ProductImage {
dynamic id;
dynamic url;
dynamic id;
dynamic url;
bool? isDefault;
dynamic productId;
dynamic productId;
ProductImage({
this.id,
@@ -249,18 +248,18 @@ class ProductImage {
}
class ProductReview {
dynamic id;
dynamic userId;
dynamic productId;
dynamic rating;
dynamic title;
dynamic description;
dynamic id;
dynamic userId;
dynamic productId;
dynamic rating;
dynamic title;
dynamic description;
dynamic likes;
dynamic dislikes;
dynamic helpfulCount;
bool? isVerified;
bool? verifiedPurchase;
dynamic status;
dynamic status;
DateTime? createdAt;
DateTime? updatedAt;
@@ -317,17 +316,17 @@ class ProductReview {
}
class Store {
dynamic id;
dynamic storeName;
dynamic storeDescription;
dynamic officialPhoneNumber;
dynamic storeAddress;
dynamic gstNumber;
dynamic gumastaNumber;
dynamic storePicture;
dynamic id;
dynamic storeName;
dynamic storeDescription;
dynamic officialPhoneNumber;
dynamic storeAddress;
dynamic gstNumber;
dynamic gumastaNumber;
dynamic storePicture;
DateTime? createdAt;
DateTime? updatedAt;
dynamic vendorId;
dynamic vendorId;
bool? isActive;
Store({

View File

@@ -161,7 +161,7 @@ class ProductProvider extends ChangeNotifier {
// Mock API call
Future<bool> addToWish(BuildContext context, String productId) async {
//context.showLoader(show: true);
print("jsdkjfhkdfkg ${productId}");
var data = {
"productId": productId,
@@ -200,14 +200,11 @@ class ProductProvider extends ChangeNotifier {
Set<String> wishlist = {}; // To store product IDs in the wishlist
// Function to add/remove product from wishlist
Future<void> toggleWishlist(BuildContext context, String productId) async {
try {
if (wishlist.contains(productId)) {
wishlist.remove(productId);
} else {
// Call the API to add to wishlist
var result = await addToWish(context, productId);
wishlist.add(productId); // Add the product ID to the wishlist
@@ -223,6 +220,16 @@ class ProductProvider extends ChangeNotifier {
}
}
void toggleWishlist1(String productId) {
for (var product in products) {
if (product.id == productId) {
product.isInWishlist = !product.isInWishlist; // Toggle value
notifyListeners(); // Refresh UI
break;
}
}
}
// Future<bool> addToCart(BuildContext context, String productId) async
// {
// //context.showLoader(show: true);
@@ -262,14 +269,14 @@ class ProductProvider extends ChangeNotifier {
// }
// }
Set<String> cartItems = {}; // Stores added cart items
Map<String, bool> isLoading = {}; // Tracks loading state per product
Set<String> cartItems = {};
Map<String, bool> isLoading = {};
Future<void> addToCart(BuildContext context, String productId) async {
if (cartItems.contains(productId)) return; // Prevent duplicate additions
isLoading[productId] = true;
notifyListeners();
notifyListeners(); // Notify UI to show loading indicator
var data = {"productId": productId, "quantity": 1};
@@ -286,7 +293,7 @@ class ProductProvider extends ChangeNotifier {
);
},
(response) {
cartItems.add(productId); // Update cart state on success
cartItems.add(productId); // Add product to cart
Fluttertoast.showToast(
msg: "Added to cart successfully!",
toastLength: Toast.LENGTH_SHORT,
@@ -295,17 +302,20 @@ class ProductProvider extends ChangeNotifier {
textColor: Colors.white,
fontSize: 14.0,
);
notifyListeners(); // Update UI after adding to cart
},
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Something went wrong"), backgroundColor: Colors.red),
content: Text("Something went wrong"),
backgroundColor: Colors.red,
),
);
} finally {
isLoading[productId] = false;
notifyListeners(); // Ensure UI updates after operation
}
isLoading[productId] = false;
notifyListeners();
}
bool isWishListItemLoadingg = true;
@@ -377,8 +387,6 @@ class ProductProvider extends ChangeNotifier {
Future<void> similarProductprovider(BuildContext context, String id) async {
var data = {};
var result = await _homeRepo.similarProduct(data, context, id);
return result.fold(
(error) {

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
@@ -107,6 +108,12 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
),
itemBuilder: (context, index) {
var product = provider.products[index];
print("jndsfkgkdfg ${product.isInWishlist}");
if (product.isInWishlist) {
provider.wishlist.add(product.id);
}
return Container(
height: itemHeight,
decoration: BoxDecoration(
@@ -150,19 +157,35 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
child: InkWell(
onTap: () async {
if (await SharedPrefUtils.getToken() !=
null) {
provider.toggleWishlist(
context, product.id!);
null)
{
if (product.isInWishlist)
{
Fluttertoast.showToast(
msg: "Item already added!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 14.0,
);
} else
{
//product.isInWishlist=ture;
provider.toggleWishlist1( product.id!);
}
} else {
context.push(MyRoutes.LOGIN);
}
},
child: Icon(
provider.wishlist.contains(product.id)
product.isInWishlist
? Icons.favorite
: Icons.favorite_border,
color: provider.wishlist
.contains(product.id)
color: product.isInWishlist
? Colors.red
: Colors.grey,
),

View File

@@ -315,56 +315,37 @@ class _HomeScreenState extends State<HomeScreen> {
],
),
// Align(
// alignment: Alignment.centerRight,
// child: InkWell(
// onTap: () async {
// bool success = await provider.addToCart(context, bestdealproduct.id!);
// if (success) {
// Fluttertoast.showToast(
// msg: "Product added to cart!",
// toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.BOTTOM,
// backgroundColor: Colors.green,
// textColor: Colors.white,
// fontSize: 14.0,
// );
// }
// },
// child: Container(
// height:
// MediaQuery.of(context).size.height * 0.035,
// width: MediaQuery.of(context).size.width * 0.1,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Add',
// style:
// context.customRegular(Colors.white, 12),
// ),
// ),
// ),
// ),
// ),
const Spacer(),
// const Spacer(),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: () async {
print(
"Add to Cart Pressed for ${bestdealproduct.id}");
if (await SharedPrefUtils.getToken() !=
null) {
provider.isLoading[bestdealproduct.id] ??
false
? null
: () => provider.addToCart(
context, bestdealproduct.id!);
if (!(provider
.isLoading[bestdealproduct.id] ??
false)) {
await provider.addToCart(
context, bestdealproduct.id!);
}
} else {
context.push(MyRoutes.LOGIN);
}
// if (await SharedPrefUtils.getToken() != null)
// {
// provider.isLoading[bestdealproduct.id] ?? false
// ? null
// : () => provider.addToCart(
// context, bestdealproduct.id!);
// } else
// {
// context.push(MyRoutes.LOGIN);
// }
},
child: Container(
height: MediaQuery.of(context).size.height *
@@ -417,8 +398,7 @@ class _HomeScreenState extends State<HomeScreen> {
} else if (provider.banner.isEmpty) {
return Center(child: Text('No products available'));
} else {
return
CarouselSlider(
return CarouselSlider(
options: CarouselOptions(
height: 180,
@@ -503,8 +483,6 @@ class _HomeScreenState extends State<HomeScreen> {
);
}).toList(),
);
}
});
}
@@ -555,7 +533,7 @@ class _HomeScreenState extends State<HomeScreen> {
height: 10,
),
Text(
"Vegitables and Fruits",
product.name ?? "",
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,

View File

@@ -6,11 +6,14 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_rating_stars/flutter_rating_stars.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
import 'package:grocery_app/src/data/allProduct_model.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/utils/constants/assets_constant.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:provider/provider.dart';
@@ -192,7 +195,7 @@ class _ProductDetailsState extends State<ProductDetails> {
style:
TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
),
similarProducts(),
bestDeal(),
SizedBox(
height: 100,
)
@@ -332,205 +335,372 @@ class _ProductDetailsState extends State<ProductDetails> {
);
}
Widget similarProducts() {
return SizedBox(
height: 222,
child: ListView.builder(
itemCount: 5,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(right: 10, bottom: 5, top: 5),
child: Container(
height: 215,
width: 150,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 1,
offset: const Offset(5, 5),
),
]),
child: Padding(
padding: const EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 100,
width: 150,
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(15)),
child: const Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height: 70,
width: 70,
imageUrl:
"https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
backGroundColor: Colors.transparent),
Positioned(
right: 5,
top: 5,
child: Icon(Icons.favorite_border))
],
),
),
Text(
"Fortune Arhar Dal (Toor Dal)",
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
const SizedBox(
height: 5,
),
Text(
"500 ML",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(
Colors.grey.withOpacity(0.8), 12),
),
const SizedBox(
height: 3,
),
Row(
children: [
Expanded(
child: Row(
children: [
Text(
"\$12",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customSemiBold(Colors.black, 12),
),
const SizedBox(
width: 5,
),
Text(
"\$14",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context
.customMedium(
Colors.grey.withOpacity(0.8), 12)
.copyWith(
decoration: TextDecoration.lineThrough,
),
),
],
)),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Container(
height: 30,
width: 50,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
'Add',
style: context.customRegular(Colors.white, 12),
)),
),
),
)
],
),
],
),
),
),
);
},
),
);
}
// Widget bottomBar() {
// return Container(
// padding: EdgeInsets.all(16),
// decoration: BoxDecoration(
// color: Colors.white,
// boxShadow: [BoxShadow(color: Colors.grey.shade300, blurRadius: 10)],
// ),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Row(
// children: [
// IconButton(
// icon: Icon(Icons.remove_circle_outline),
// onPressed: () {
// if (quantity > 1) {
// setState(() => quantity--);
// }
// },
// Widget similarProducts() {
// return SizedBox(
// height: 222,
// child: ListView.builder(
// itemCount: 5,
// scrollDirection: Axis.horizontal,
// itemBuilder: (context, index) {
// return Padding(
// padding: const EdgeInsets.only(right: 10, bottom: 5, top: 5),
// child: Container(
// height: 215,
// width: 150,
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15),
// boxShadow: [
// BoxShadow(
// color: Colors.grey.withOpacity(0.1),
// blurRadius: 1,
// offset: const Offset(5, 5),
// ),
// ]),
// child: Padding(
// padding: const EdgeInsets.all(5),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Container(
// height: 100,
// width: 150,
// decoration: BoxDecoration(
// color: APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(15)),
// child: const Stack(
// alignment: Alignment.center,
// children: [
// AppNetworkImage(
// height: 70,
// width: 70,
// imageUrl:
// "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
// backGroundColor: Colors.transparent),
// Positioned(
// right: 5,
// top: 5,
// child: Icon(Icons.favorite_border))
// ],
// ),
// ),
// Text(
// "Fortune Arhar Dal (Toor Dal)",
// textAlign: TextAlign.left,
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
// ),
// const SizedBox(
// height: 5,
// ),
// Text(
// "500 ML",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(
// Colors.grey.withOpacity(0.8), 12),
// ),
// const SizedBox(
// height: 3,
// ),
// Row(
// children: [
// Expanded(
// child: Row(
// children: [
// Text(
// "\$12",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customSemiBold(Colors.black, 12),
// ),
// const SizedBox(
// width: 5,
// ),
// Text(
// "\$14",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context
// .customMedium(
// Colors.grey.withOpacity(0.8), 12)
// .copyWith(
// decoration: TextDecoration.lineThrough,
// ),
// ),
// ],
// )),
// Expanded(
// child: Align(
// alignment: Alignment.centerRight,
// child: Container(
// height: 30,
// width: 50,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Add',
// style: context.customRegular(Colors.white, 12),
// )),
// ),
// ),
// )
// ],
// ),
// ],
// ),
// ),
// Text("$quantity",
// style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
// IconButton(
// icon: Icon(Icons.add_circle_outline),
// onPressed: () => setState(() => quantity++),
// ),
// ],
// ),
// Container(
// height: 50,
// // width: 0,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Padding(
// padding: const EdgeInsets.all(8.0),
// child: Center(
// child: Row(
// children: [
// Text(
// 'Add to Cart',
// style: TextStyle(
// fontSize: 20,
// fontWeight: FontWeight.bold,
// color: Colors.white),
// ),
// SizedBox(
// width: 20,
// ),
// Container(width: 2, height: 50, color: APPCOLOR.whiteFBFEFB),
// SizedBox(
// width: 20,
// ),
// Text(
// "\$${widget.product.discountPrice ?? ""}",
// style: TextStyle(
// fontSize: 25,
// fontWeight: FontWeight.bold,
// color: Colors.white),
// ),
// ],
// )),
// ),
// )
// ],
// );
// },
// ),
// );
// }
Widget bestDeal() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isBestdealingloading) {
return Center(child: CircularProgressIndicator());
} else if (provider.bestdeal.isEmpty) {
return Center(child: Text('No products available'));
} else {
return SizedBox(
height: MediaQuery.of(context).size.height * 0.28,
child: ListView.builder(
itemCount: provider.bestdeal.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
var bestdealproduct = provider.bestdeal[index];
double cardWidth =
MediaQuery.of(context).size.width * 0.4; // Dynamic width
return Padding(
padding: const EdgeInsets.only(right: 10, bottom: 5, top: 5),
child: Container(
width: cardWidth,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 1,
offset: const Offset(5, 5),
),
],
),
child: Padding(
padding: const EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
height: MediaQuery.of(context).size.height * 0.12,
width: cardWidth * 0.9,
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(15),
),
child: Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height:
MediaQuery.of(context).size.height * 0.08,
width: cardWidth * 0.7,
imageUrl: bestdealproduct
.productImages?.first?.url ??
"",
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,
),
),
),
],
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Text(
bestdealproduct.name ?? "",
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.005,
),
Text(
bestdealproduct.unit ?? "",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(
Colors.grey.withOpacity(0.8),
12,
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.005,
),
const Spacer(),
Row(
children: [
Row(
children: [
Text(
"\$${bestdealproduct.discountPrice ?? ""} ",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style:
context.customSemiBold(Colors.black, 12),
),
Text(
"\$${bestdealproduct.basePrice ?? ""}",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context
.customMedium(
Colors.grey.withOpacity(0.8),
12,
)
.copyWith(
decoration: TextDecoration.lineThrough,
),
),
],
),
// Align(
// alignment: Alignment.centerRight,
// child: InkWell(
// onTap: () async {
// bool success = await provider.addToCart(context, bestdealproduct.id!);
// if (success) {
// Fluttertoast.showToast(
// msg: "Product added to cart!",
// toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.BOTTOM,
// backgroundColor: Colors.green,
// textColor: Colors.white,
// fontSize: 14.0,
// );
// }
// },
// child: Container(
// height:
// MediaQuery.of(context).size.height * 0.035,
// width: MediaQuery.of(context).size.width * 0.1,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Add',
// style:
// context.customRegular(Colors.white, 12),
// ),
// ),
// ),
// ),
// ),
const Spacer(),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: () async {
if (await SharedPrefUtils.getToken() !=
null) {
provider.isLoading[bestdealproduct.id] ??
false
? null
: () => provider.addToCart(
context, bestdealproduct.id!);
} else {
context.push(MyRoutes.LOGIN);
}
},
child: Container(
height: MediaQuery.of(context).size.height *
0.035,
width:
MediaQuery.of(context).size.width * 0.1,
decoration: BoxDecoration(
color: provider.cartItems
.contains(bestdealproduct.id)
? Colors.grey
: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: provider.isLoading[
bestdealproduct.id] ??
false
? CircularProgressIndicator(
color: Colors.white, strokeWidth: 2)
: Text(
provider.cartItems.contains(
bestdealproduct.id)
? 'Added'
: 'Add',
style: context.customRegular(
Colors.white, 12),
),
),
),
),
),
],
),
],
),
),
),
);
},
),
);
}
});
}
Widget bottomBar() {
return Consumer<ProductProvider>(
builder: (context, cartProvider, child) {