payfrit-app/lib/app/app_state.dart
John Mizerek c445664df8 Implement production-ready beacon auto-selection system
- Multi-cycle BLE scanning (5 cycles x 2 seconds) overcomes Android detection limits
- RSSI averaging and variance calculation for confident beacon selection
- Detects all 3 test beacons with 100% accuracy
- Login flow optimized: beacon scan → browse menu → login on cart add
- Anonymous users can browse full menu before authentication
- Beacon scanning now occurs before login requirement

Technical improvements:
- Added API endpoints for beacon listing and business mapping
- Updated AppState to handle business/service point selection
- Implemented intelligent beacon scoring with proximity ranking
- Added graceful fallbacks for no-beacon scenarios

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 23:01:23 -08:00

96 lines
2 KiB
Dart

import "package:flutter/foundation.dart";
class AppState extends ChangeNotifier {
int? _selectedBusinessId;
int? _selectedServicePointId;
int? _userId;
int? _cartOrderId;
String? _cartOrderUuid;
int _cartItemCount = 0;
int? get selectedBusinessId => _selectedBusinessId;
int? get selectedServicePointId => _selectedServicePointId;
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) {
_selectedBusinessId = businessId;
_selectedServicePointId = servicePointId;
_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;
}
}