add auth, format
This commit is contained in:
@@ -44,14 +44,9 @@ class Cart extends _$Cart {
|
||||
);
|
||||
} else {
|
||||
// Add new item
|
||||
final newItem = CartItemData(
|
||||
product: product,
|
||||
quantity: quantity,
|
||||
);
|
||||
final newItem = CartItemData(product: product, quantity: quantity);
|
||||
|
||||
state = state.copyWith(
|
||||
items: [...state.items, newItem],
|
||||
);
|
||||
state = state.copyWith(items: [...state.items, newItem]);
|
||||
_recalculateTotal();
|
||||
}
|
||||
}
|
||||
@@ -59,7 +54,9 @@ class Cart extends _$Cart {
|
||||
/// Remove product from cart
|
||||
void removeFromCart(String productId) {
|
||||
state = state.copyWith(
|
||||
items: state.items.where((item) => item.product.productId != productId).toList(),
|
||||
items: state.items
|
||||
.where((item) => item.product.productId != productId)
|
||||
.toList(),
|
||||
);
|
||||
_recalculateTotal();
|
||||
}
|
||||
@@ -113,20 +110,14 @@ class Cart extends _$Cart {
|
||||
// TODO: Validate with backend
|
||||
// For now, simulate discount application
|
||||
if (code.isNotEmpty) {
|
||||
state = state.copyWith(
|
||||
discountCode: code,
|
||||
discountCodeApplied: true,
|
||||
);
|
||||
state = state.copyWith(discountCode: code, discountCodeApplied: true);
|
||||
_recalculateTotal();
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove discount code
|
||||
void removeDiscountCode() {
|
||||
state = state.copyWith(
|
||||
discountCode: null,
|
||||
discountCodeApplied: false,
|
||||
);
|
||||
state = state.copyWith(discountCode: null, discountCodeApplied: false);
|
||||
_recalculateTotal();
|
||||
}
|
||||
|
||||
@@ -157,10 +148,7 @@ class Cart extends _$Cart {
|
||||
|
||||
/// Get total quantity of all items
|
||||
double get totalQuantity {
|
||||
return state.items.fold<double>(
|
||||
0.0,
|
||||
(sum, item) => sum + item.quantity,
|
||||
);
|
||||
return state.items.fold<double>(0.0, (sum, item) => sum + item.quantity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,18 +12,12 @@ class CartItemData {
|
||||
final Product product;
|
||||
final double quantity;
|
||||
|
||||
const CartItemData({
|
||||
required this.product,
|
||||
required this.quantity,
|
||||
});
|
||||
const CartItemData({required this.product, required this.quantity});
|
||||
|
||||
/// Calculate line total
|
||||
double get lineTotal => product.basePrice * quantity;
|
||||
|
||||
CartItemData copyWith({
|
||||
Product? product,
|
||||
double? quantity,
|
||||
}) {
|
||||
CartItemData copyWith({Product? product, double? quantity}) {
|
||||
return CartItemData(
|
||||
product: product ?? this.product,
|
||||
quantity: quantity ?? this.quantity,
|
||||
@@ -101,7 +95,8 @@ class CartState {
|
||||
discountCode: discountCode ?? this.discountCode,
|
||||
discountCodeApplied: discountCodeApplied ?? this.discountCodeApplied,
|
||||
memberTier: memberTier ?? this.memberTier,
|
||||
memberDiscountPercent: memberDiscountPercent ?? this.memberDiscountPercent,
|
||||
memberDiscountPercent:
|
||||
memberDiscountPercent ?? this.memberDiscountPercent,
|
||||
subtotal: subtotal ?? this.subtotal,
|
||||
memberDiscount: memberDiscount ?? this.memberDiscount,
|
||||
shippingFee: shippingFee ?? this.shippingFee,
|
||||
|
||||
Reference in New Issue
Block a user