UI Improvements: - Menu items displayed as attractive cards with icons and better typography - Restaurant selection upgraded to card-based layout with shadows - Animated pulsing beacon scanner with gradient effect - Enhanced item customization sheet with drag handle and pill-style pricing - Category headers with highlighted background and borders - Business and service point names now shown in app bar Persistent Login: - Created AuthStorage service for credential persistence using SharedPreferences - Auto-restore authentication on app launch - Seamless login flow: scan → browse → login on cart add - Users stay logged in across app restarts Cart Functionality Fixes: - Fixed duplicate item handling: now properly increments quantity - Prevented adding inactive items by skipping unselected modifiers - Fixed self-referential items (item cannot be its own child) - Added debug logging for cart state tracking - Success messages now show accurate item counts Technical Improvements: - AppState tracks business/service point names for display - Beacon scanner passes location names through navigation - Quantity calculation checks existing cart items before adding - Better null safety with firstOrNull pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
107 lines
2.3 KiB
Dart
107 lines
2.3 KiB
Dart
import "package:flutter/foundation.dart";
|
|
|
|
class AppState extends ChangeNotifier {
|
|
int? _selectedBusinessId;
|
|
String? _selectedBusinessName;
|
|
int? _selectedServicePointId;
|
|
String? _selectedServicePointName;
|
|
|
|
int? _userId;
|
|
|
|
int? _cartOrderId;
|
|
String? _cartOrderUuid;
|
|
int _cartItemCount = 0;
|
|
|
|
|
|
int? get selectedBusinessId => _selectedBusinessId;
|
|
String? get selectedBusinessName => _selectedBusinessName;
|
|
int? get selectedServicePointId => _selectedServicePointId;
|
|
String? get selectedServicePointName => _selectedServicePointName;
|
|
|
|
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 setBusinessAndServicePoint(
|
|
int businessId,
|
|
int servicePointId, {
|
|
String? businessName,
|
|
String? servicePointName,
|
|
}) {
|
|
_selectedBusinessId = businessId;
|
|
_selectedBusinessName = businessName;
|
|
_selectedServicePointId = servicePointId;
|
|
_selectedServicePointName = servicePointName;
|
|
|
|
_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;
|
|
|
|
|
|
}
|
|
}
|