add auth, format

This commit is contained in:
Phuoc Nguyen
2025-11-07 11:52:06 +07:00
parent 24a8508fce
commit 3803bd26e0
173 changed files with 8505 additions and 7116 deletions

View File

@@ -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);
}
}