Client-side implementation: - New service: order_polling_service.dart - Timer-based polling every 30s - Updated AppState: track active order ID and current status - Cart integration: start polling after order submission - In-app notifications: color-coded SnackBar for status changes - Notification widget: animated banner (created for future use) Status notification colors: - Blue = Submitted (1) - Orange = Preparing (2) - Green = Ready (3) - Purple = Completed (4) Polling workflow: 1. User submits order → polling starts with status=1 2. Every 30s: check backend for status changes 3. On update: show notification + update AppState 4. Continues until order completed or app closed Simple polling approach (Option 2) with planned migration to self-hosted WebSocket push for instant updates. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
129 lines
2.9 KiB
Dart
129 lines
2.9 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;
|
|
|
|
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 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;
|
|
|
|
_activeOrderId = null;
|
|
_activeOrderStatusId = null;
|
|
}
|
|
}
|