productdetails

This commit is contained in:
2025-01-31 19:02:20 +05:30
parent 028155a1d7
commit 42aaa7cdad
32 changed files with 2803 additions and 1987 deletions

View File

@@ -7,6 +7,7 @@ import 'package:grocery_app/src/data/all_cart_items.dart';
import 'package:grocery_app/src/data/banners.dart';
import 'package:grocery_app/src/data/best_dealProduct.dart';
import 'package:grocery_app/src/data/product_category.dart';
import 'package:grocery_app/src/data/product_details.dart';
import 'package:grocery_app/src/data/wish_list_model.dart';
import 'package:grocery_app/src/logic/repo/product_repo.dart';
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
@@ -38,6 +39,29 @@ class ProductProvider extends ChangeNotifier {
);
}
ProductDetailsData productDetails = ProductDetailsData();
bool isProductLoading = true;
Future<void> getProduuctDetails(BuildContext context, String id) async {
var data = {};
productDetails = ProductDetailsData();
isProductLoading = true;
notifyListeners();
var result = await _homeRepo.getProductDetails(data, context, id);
return result.fold(
(error) {
isProductLoading = false;
notifyListeners();
},
(response) {
productDetails = response!;
isProductLoading = false;
notifyListeners();
},
);
}
List<BestDeal> bestdeal = [];
bool isBestdealingloading = true;
@@ -132,7 +156,7 @@ class ProductProvider extends ChangeNotifier {
),
);
await SharedPrefUtils.clear();
context.clearAndPush(routePath: MyRoutes.LOGIN);
context.clearAndPush(routePath: MyRoutes.SIGNUP);
return true;
},
@@ -319,6 +343,56 @@ class ProductProvider extends ChangeNotifier {
}
}
List<BestDeal> countList = [];
Future<void> addToWithCart(
BuildContext context, String productId, BestDeal bestdealproduct) async {
//if (cartItems.contains(productId)) return; // Prevent duplicate additions
isLoading[productId] = true;
notifyListeners(); // Notify UI to show loading indicator
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) {
countList.add(bestdealproduct);
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 = [];
@@ -360,8 +434,7 @@ class ProductProvider extends ChangeNotifier {
int get quantity => _quantity;
double get totalPrice => _totalPrice;
void setProductPrice(double price)
{
void setProductPrice(double price) {
_unitPrice = price;
_totalPrice = _unitPrice * _quantity;
notifyListeners();
@@ -406,6 +479,4 @@ class ProductProvider extends ChangeNotifier {
}
///////////////////////////////////////////////////// all carts////////////////////////
}