Snackbar Improvements: - All snackbars now have colored backgrounds (green/red/orange/blue) - Added icons to snackbar messages (check_circle, error, warning, info) - Floating behavior with bottom margin to avoid obscuring action buttons - Consistent styling across menu_browse, cart_view, and login screens App State Fixes: - Clear cartItemCount when switching businesses (setBusiness, setServicePoint, setBusinessAndServicePoint, clearAll) - Prevents stale cart count showing after switching restaurants 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
133 lines
3 KiB
Dart
133 lines
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? _activeOrderId;
|
|
int? _activeOrderStatusId;
|
|
|
|
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;
|
|
|
|
int? get activeOrderId => _activeOrderId;
|
|
int? get activeOrderStatusId => _activeOrderStatusId;
|
|
|
|
|
|
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 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 clearAll() {
|
|
_selectedBusinessId = null;
|
|
_selectedServicePointId = null;
|
|
|
|
_cartOrderId = null;
|
|
_cartOrderUuid = null;
|
|
_cartItemCount = 0;
|
|
|
|
_activeOrderId = null;
|
|
_activeOrderStatusId = null;
|
|
}
|
|
}
|