updateProfile

This commit is contained in:
2025-02-03 01:29:42 +05:30
parent 42aaa7cdad
commit 1f7254ecaa
48 changed files with 6088 additions and 2473 deletions

View File

@@ -46,6 +46,8 @@ class ProductProvider extends ChangeNotifier {
var data = {};
productDetails = ProductDetailsData();
isProductLoading = true;
quantitys = 1;
_totalPrice = 0.0;
notifyListeners();
var result = await _homeRepo.getProductDetails(data, context, id);
@@ -186,8 +188,6 @@ class ProductProvider extends ChangeNotifier {
// Mock API call
Future<bool> addToWish(BuildContext context, String productId) async {
print("jsdkjfhkdfkg ${productId}");
var data = {
"productId": productId,
};
@@ -206,6 +206,7 @@ class ProductProvider extends ChangeNotifier {
return false;
},
(response) {
iswishloading = false;
Fluttertoast.showToast(
msg: "Wishlist updated successfully!",
toastLength: Toast.LENGTH_SHORT,
@@ -223,18 +224,24 @@ class ProductProvider extends ChangeNotifier {
}
}
Set<String> wishlist = {}; // To store product IDs in the wishlist
Set<String> wishlist = {};
bool iswishloading = false;
Future<void> toggleWishlist(BuildContext context, String productId) async {
iswishloading = true;
notifyListeners();
try {
if (wishlist.contains(productId)) {
wishlist.remove(productId);
iswishloading = false;
} else {
var result = await addToWish(context, productId);
wishlist.add(productId); // Add the product ID to the wishlist
wishlist.add(productId);
}
notifyListeners(); // Notify listeners to update the UI
iswishloading = false;
notifyListeners();
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
@@ -297,13 +304,16 @@ class ProductProvider extends ChangeNotifier {
Set<String> cartItems = {};
Map<String, bool> isLoading = {};
Future<void> addToCart(BuildContext context, String productId) async {
//if (cartItems.contains(productId)) return; // Prevent duplicate additions
bool isLoadingCart=false;
bool iscardAdded=false;
Future<void> addToCart(BuildContext context, String productId,int quantity) async {
//if (cartItems.contains(productId)) return; // Prevent duplicate additions
isLoadingCart=true;
isLoading[productId] = true;
notifyListeners(); // Notify UI to show loading indicator
var data = {"productId": productId, "quantity": 1};
var data = {"productId": productId, "quantity": quantity};
try {
var result = await _homeRepo.addToCart(data);
@@ -327,6 +337,7 @@ class ProductProvider extends ChangeNotifier {
textColor: Colors.white,
fontSize: 14.0,
);
iscardAdded=true;
notifyListeners(); // Update UI after adding to cart
},
);
@@ -338,19 +349,20 @@ class ProductProvider extends ChangeNotifier {
),
);
} finally {
isLoadingCart=false;
isLoading[productId] = false;
notifyListeners(); // Ensure UI updates after operation
}
}
List<BestDeal> countList = [];
String lastImageurl = '';
Future<void> addToWithCart(
BuildContext context, String productId, BestDeal bestdealproduct) async {
//if (cartItems.contains(productId)) return; // Prevent duplicate additions
Future<void> addToWithCart(BuildContext context, String productId,
BestDeal bestdealproduct, url) async {
isLoading[productId] = true;
notifyListeners(); // Notify UI to show loading indicator
notifyListeners();
var data = {"productId": productId, "quantity": 1};
@@ -368,6 +380,7 @@ class ProductProvider extends ChangeNotifier {
},
(response) {
countList.add(bestdealproduct);
lastImageurl = url;
cartItems.add(productId); // Add product to cart
Fluttertoast.showToast(
msg: "Added to cart successfully!",
@@ -393,6 +406,63 @@ class ProductProvider extends ChangeNotifier {
}
}
List<ProductDatum> productDatum = [];
String productDatumlastImageurl = '';
Future<void> addToCartWithWishlist(BuildContext context, String productId,ProductDatum productdataum,
url) async {
isLoading[productId] = true;
notifyListeners();
var data = {"productId": productId, "quantity": 1};
try {
var result = await _homeRepo.addToCart(data);
result.fold(
(error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(error.message),
backgroundColor: Colors.red,
),
);
},
(response) {
productDatum.add(productdataum);
productDatumlastImageurl = url;
cartItems.add(productId); // Add product to cart
Fluttertoast.showToast(
msg: "Added to cart successfully!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
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,
),
);
} finally {
isLoading[productId] = false;
notifyListeners(); // Ensure UI updates after operation
}
}
bool isWishListItemLoadingg = true;
List<WishListItem> wishListItem = [];
@@ -427,30 +497,69 @@ class ProductProvider extends ChangeNotifier {
}
////////////////////////////// product increase ////////////////////////////////////
int _quantity = 1;
int quantitys = 1;
double _unitPrice = 0.0;
double _totalPrice = 0.0;
int get quantity => _quantity;
int get quantity => quantitys;
double get totalPrice => _totalPrice;
void setProductPrice(double price) {
_unitPrice = price;
_totalPrice = _unitPrice * _quantity;
_totalPrice = _unitPrice * quantitys;
notifyListeners();
}
int productQuantity = 0;
// void increaseQuantity()
// {
// if(quantity<10)
// if (_quantity < 10)
// {
// // Limit to 10
// _quantity++;
// _totalPrice = _unitPrice * _quantity;
// notifyListeners();
// }
// {
// Fluttertoast.showToast(
// msg: "Sorry cart successfully!",
// toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.BOTTOM,
// backgroundColor: Colors.green,
// textColor: Colors.white,
// fontSize: 14.0,
// );
// }
// }
void increaseQuantity() {
print("kjfgkhkdfhgkjdhfg");
_quantity++;
_totalPrice = _unitPrice * _quantity;
notifyListeners();
int maxAllowed = productQuantity >= 100
? 10
: productQuantity; // Max limit based on stock
if (quantitys < maxAllowed) {
quantitys++;
_totalPrice = _unitPrice * quantitys;
notifyListeners();
} else {
Fluttertoast.showToast(
msg: "Sorry, you can only add up to $maxAllowed items!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 14.0,
);
}
}
void decreaseQuantity() {
if (_quantity > 1) {
_quantity--;
_totalPrice = _unitPrice * _quantity;
if (quantitys > 1) {
quantitys--;
_totalPrice = _unitPrice * quantitys;
notifyListeners();
}
}