add firebase, add screen flow
This commit is contained in:
@@ -32,7 +32,7 @@ class CartRepositoryImpl implements CartRepository {
|
||||
final CartLocalDataSource _localDataSource;
|
||||
|
||||
@override
|
||||
Future<List<CartItem>> addToCart({
|
||||
Future<bool> addToCart({
|
||||
required List<String> itemIds,
|
||||
required List<double> quantities,
|
||||
required List<double> prices,
|
||||
@@ -57,17 +57,24 @@ class CartRepositoryImpl implements CartRepository {
|
||||
|
||||
// Try API first
|
||||
try {
|
||||
final cartItemModels = await _remoteDataSource.addToCart(items: items);
|
||||
final success = await _remoteDataSource.addToCart(items: items);
|
||||
|
||||
// Sync to local storage
|
||||
await _localDataSource.saveCartItems(cartItemModels);
|
||||
// Also save to local storage for offline access
|
||||
if (success) {
|
||||
for (int i = 0; i < itemIds.length; i++) {
|
||||
final cartItemModel = _createCartItemModel(
|
||||
productId: itemIds[i],
|
||||
quantity: quantities[i],
|
||||
unitPrice: prices[i],
|
||||
);
|
||||
await _localDataSource.addCartItem(cartItemModel);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert to domain entities
|
||||
return cartItemModels.map(_modelToEntity).toList();
|
||||
return success;
|
||||
} on NetworkException catch (e) {
|
||||
// If no internet, add to local cart only
|
||||
if (e is NoInternetException || e is TimeoutException) {
|
||||
// Add items to local cart
|
||||
for (int i = 0; i < itemIds.length; i++) {
|
||||
final cartItemModel = _createCartItemModel(
|
||||
productId: itemIds[i],
|
||||
@@ -79,9 +86,7 @@ class CartRepositoryImpl implements CartRepository {
|
||||
|
||||
// TODO: Queue for sync when online
|
||||
|
||||
// Return local cart items
|
||||
final localItems = await _localDataSource.getCartItems();
|
||||
return localItems.map(_modelToEntity).toList();
|
||||
return true;
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
@@ -167,7 +172,7 @@ class CartRepositoryImpl implements CartRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<CartItem>> updateQuantity({
|
||||
Future<bool> updateQuantity({
|
||||
required String itemId,
|
||||
required double quantity,
|
||||
required double price,
|
||||
|
||||
Reference in New Issue
Block a user