payfrit-app/lib/app/app_state.dart
John Mizerek f505eeb722 Implement complete cart management system
Add full cart functionality with API integration:
- Created Cart and OrderLineItem models with robust JSON parsing
- Implemented cart API methods (getOrCreateCart, setLineItem, getCart, submitOrder)
- Added cart state management to AppState with item count tracking
- Built cart view screen with item display, quantity editing, and removal
- Added cart badge to menu screen showing item count
- Implemented real add-to-cart logic with recursive modifier handling
- Added category name display in menu browsing
- Fixed API response case sensitivity (ORDER/ORDERLINEITEMS)
- Enhanced MenuItem model with categoryName field

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-29 11:14:19 -08:00

83 lines
1.8 KiB
Dart

import "package:flutter/foundation.dart";
class AppState extends ChangeNotifier {
int? _selectedBusinessId;
int? _selectedServicePointId;
int? _userId;
int? _cartOrderId;
String? _cartOrderUuid;
int _cartItemCount = 0;
int? get selectedBusinessId => _selectedBusinessId;
int? get selectedServicePointId => _selectedServicePointId;
int? get userId => _userId;
bool get isLoggedIn => _userId != null && _userId! > 0;
int? get cartOrderId => _cartOrderId;
String? get cartOrderUuid => _cartOrderUuid;
int get cartItemCount => _cartItemCount;
bool get hasLocationSelection =>
_selectedBusinessId != null && _selectedServicePointId != null;
void setBusiness(int businessId) {
_selectedBusinessId = businessId;
_selectedServicePointId = null;
_cartOrderId = null;
_cartOrderUuid = null;
notifyListeners();
}
void setServicePoint(int servicePointId) {
_selectedServicePointId = servicePointId;
_cartOrderId = null;
_cartOrderUuid = null;
notifyListeners();
}
void setUserId(int userId) {
_userId = userId;
notifyListeners();
}
void clearAuth() {
_userId = null;
notifyListeners();
}
void setCartOrder({required int orderId, required String orderUuid, int itemCount = 0}) {
_cartOrderId = orderId;
_cartOrderUuid = orderUuid;
_cartItemCount = itemCount;
notifyListeners();
}
void updateCartItemCount(int count) {
_cartItemCount = count;
notifyListeners();
}
void clearCart() {
_cartOrderId = null;
_cartOrderUuid = null;
_cartItemCount = 0;
notifyListeners();
}
void clearAll() {
_selectedBusinessId = null;
_selectedServicePointId = null;
_cartOrderId = null;
_cartOrderUuid = null;
notifyListeners();
}
}