payfrit-app/lib/app/app_state.dart
John Mizerek 65b5b82546 Add customer-to-staff chat feature and group order invites
- Add real-time chat between customers and staff via WebSocket
- Add HTTP polling fallback when WebSocket unavailable
- Chat auto-closes when worker ends conversation with dialog notification
- Add user search API for group order invites (phone/email/name)
- Store group order invites in app state
- Add login check before starting chat with sign-in prompt
- Remove table change button (not allowed currently)
- Fix About screen to show dynamic version from pubspec
- Update snackbar styling to green with black text

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 12:08:09 -08:00

169 lines
3.9 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;
int? _userId;
OrderType? _orderType;
int? _cartOrderId;
String? _cartOrderUuid;
int _cartItemCount = 0;
int? _activeOrderId;
int? _activeOrderStatusId;
List<int> _groupOrderInvites = [];
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;
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;
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,
}) {
_selectedBusinessId = businessId;
_selectedBusinessName = businessName;
_selectedServicePointId = servicePointId;
_selectedServicePointName = servicePointName;
_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 clearAll() {
_selectedBusinessId = null;
_selectedServicePointId = null;
_orderType = null;
_cartOrderId = null;
_cartOrderUuid = null;
_cartItemCount = 0;
_activeOrderId = null;
_activeOrderStatusId = null;
_groupOrderInvites = [];
}
}