This commit is contained in:
Phuoc Nguyen
2025-10-10 16:38:07 +07:00
parent e5b247d622
commit b94c158004
177 changed files with 25080 additions and 152 deletions

View File

@@ -0,0 +1,54 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../domain/entities/cart_item.dart';
part 'cart_provider.g.dart';
/// Provider for shopping cart
@riverpod
class Cart extends _$Cart {
@override
Future<List<CartItem>> build() async {
// TODO: Implement with repository
return [];
}
Future<void> addItem(CartItem item) async {
// TODO: Implement add to cart
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
final currentItems = state.value ?? [];
return [...currentItems, item];
});
}
Future<void> removeItem(String productId) async {
// TODO: Implement remove from cart
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
final currentItems = state.value ?? [];
return currentItems.where((item) => item.productId != productId).toList();
});
}
Future<void> updateQuantity(String productId, int quantity) async {
// TODO: Implement update quantity
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
final currentItems = state.value ?? [];
return currentItems.map((item) {
if (item.productId == productId) {
return item.copyWith(quantity: quantity);
}
return item;
}).toList();
});
}
Future<void> clearCart() async {
// TODO: Implement clear cart
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
return [];
});
}
}