payfrit-app/lib/app/app_state.dart
John Mizerek c4792189dd App Store Version 2: Beacon scanning, preload caching, business selector
Features:
- Beacon scanner service for detecting nearby beacons
- Beacon cache for offline-first beacon resolution
- Preload cache for instant menu display
- Business selector screen for multi-location support
- Rescan button widget for quick beacon refresh
- Sign-in dialog for guest checkout flow
- Task type model for server tasks

Improvements:
- Enhanced menu browsing with category filtering
- Improved cart view with better modifier display
- Order history with detailed order tracking
- Chat screen improvements
- Better error handling in API service

Fixes:
- CashApp payment return crash fix
- Modifier nesting issues resolved
- Auto-expand modifier groups

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 19:51:54 -08:00

190 lines
4.5 KiB
Dart

import "package:flutter/foundation.dart";
enum OrderType {
dineIn, // Table service (beacon detected)
delivery, // Delivery to customer
takeaway, // Pickup at counter
}
class AppState extends ChangeNotifier {
int? _selectedBusinessId;
String? _selectedBusinessName;
int? _selectedServicePointId;
String? _selectedServicePointName;
// Parent business info (for back navigation when selected from business selector)
int? _parentBusinessId;
String? _parentBusinessName;
int? _userId;
OrderType? _orderType;
int? _cartOrderId;
String? _cartOrderUuid;
int _cartItemCount = 0;
int? _activeOrderId;
int? _activeOrderStatusId;
List<int> _groupOrderInvites = [];
String? _brandColor;
int? get selectedBusinessId => _selectedBusinessId;
String? get selectedBusinessName => _selectedBusinessName;
int? get selectedServicePointId => _selectedServicePointId;
String? get selectedServicePointName => _selectedServicePointName;
int? get parentBusinessId => _parentBusinessId;
String? get parentBusinessName => _parentBusinessName;
bool get hasParentBusiness => _parentBusinessId != null;
int? get userId => _userId;
bool get isLoggedIn => _userId != null && _userId! > 0;
OrderType? get orderType => _orderType;
bool get isDelivery => _orderType == OrderType.delivery;
bool get isTakeaway => _orderType == OrderType.takeaway;
bool get isDineIn => _orderType == OrderType.dineIn;
int? get cartOrderId => _cartOrderId;
String? get cartOrderUuid => _cartOrderUuid;
int get cartItemCount => _cartItemCount;
int? get activeOrderId => _activeOrderId;
int? get activeOrderStatusId => _activeOrderStatusId;
bool get hasActiveOrder => _activeOrderId != null;
List<int> get groupOrderInvites => _groupOrderInvites;
bool get isGroupOrder => _groupOrderInvites.isNotEmpty;
String? get brandColor => _brandColor;
bool get hasLocationSelection =>
_selectedBusinessId != null && _selectedServicePointId != null;
void setBusiness(int businessId) {
_selectedBusinessId = businessId;
_selectedServicePointId = null;
_cartOrderId = null;
_cartOrderUuid = null;
_cartItemCount = 0;
notifyListeners();
}
void setServicePoint(int servicePointId) {
_selectedServicePointId = servicePointId;
_cartOrderId = null;
_cartOrderUuid = null;
_cartItemCount = 0;
notifyListeners();
}
void setBusinessAndServicePoint(
int businessId,
int servicePointId, {
String? businessName,
String? servicePointName,
int? parentBusinessId,
String? parentBusinessName,
}) {
_selectedBusinessId = businessId;
_selectedBusinessName = businessName;
_selectedServicePointId = servicePointId;
_selectedServicePointName = servicePointName;
_parentBusinessId = parentBusinessId;
_parentBusinessName = parentBusinessName;
_cartOrderId = null;
_cartOrderUuid = null;
_cartItemCount = 0;
notifyListeners();
}
void setUserId(int userId) {
_userId = userId;
notifyListeners();
}
void clearAuth() {
_userId = null;
notifyListeners();
}
void setOrderType(OrderType? type) {
_orderType = type;
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 setActiveOrder({required int orderId, required int statusId}) {
_activeOrderId = orderId;
_activeOrderStatusId = statusId;
notifyListeners();
}
void updateActiveOrderStatus(int statusId) {
_activeOrderStatusId = statusId;
notifyListeners();
}
void clearActiveOrder() {
_activeOrderId = null;
_activeOrderStatusId = null;
notifyListeners();
}
void setGroupOrderInvites(List<int> userIds) {
_groupOrderInvites = userIds;
notifyListeners();
}
void clearGroupOrderInvites() {
_groupOrderInvites = [];
notifyListeners();
}
void setBrandColor(String? color) {
_brandColor = color;
notifyListeners();
}
void clearAll() {
_selectedBusinessId = null;
_selectedServicePointId = null;
_orderType = null;
_cartOrderId = null;
_cartOrderUuid = null;
_cartItemCount = 0;
_activeOrderId = null;
_activeOrderStatusId = null;
_groupOrderInvites = [];
}
}