124 lines
4.9 KiB
Dart
124 lines
4.9 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class PickupController extends GetxController {
|
|
// Exposed reactive fields if needed in UI
|
|
final RxString orderId = ''.obs;
|
|
final RxString orderStatus = ''.obs;
|
|
final RxInt tenantId = 0.obs;
|
|
final RxInt partnerId = 0.obs;
|
|
final RxInt locationId = 0.obs;
|
|
final RxInt orderHeaderId = 0.obs;
|
|
final RxInt pickupId = 0.obs;
|
|
final RxInt userId = 0.obs;
|
|
final RxString latitude = ''.obs;
|
|
final RxString longitude = ''.obs;
|
|
|
|
// Preference keys (aligned with existing usage in app)
|
|
static const String kTenantId = 'pickup_tenantid';
|
|
static const String kPartnerId = 'pickup_partnerid';
|
|
static const String kLocationId = 'pickup_locationid';
|
|
static const String kOrderHeaderId = 'pickup_orderheaderid';
|
|
static const String kPickupId = 'pickup_pickupid';
|
|
static const String kUserId = 'pickup_userid';
|
|
static const String kOrderId = 'pickup_orderid';
|
|
static const String kOrderStatus = 'pickup_orderstatus';
|
|
static const String kLat = 'pickup_latitude';
|
|
static const String kLng = 'pickup_longitude';
|
|
|
|
Future<void> saveFromQueueItem(Map<String, dynamic> pickup) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
final int? tenantid = pickup['tenantid'] is int
|
|
? pickup['tenantid'] as int
|
|
: int.tryParse('${pickup['tenantid'] ?? ''}');
|
|
final int? partnerid = pickup['partnerid'] is int
|
|
? pickup['partnerid'] as int
|
|
: int.tryParse('${pickup['partnerid'] ?? ''}');
|
|
final int? locationid = pickup['locationid'] is int
|
|
? pickup['locationid'] as int
|
|
: int.tryParse('${pickup['locationid'] ?? ''}');
|
|
final int? orderheaderid = pickup['orderheaderid'] is int
|
|
? pickup['orderheaderid'] as int
|
|
: int.tryParse('${pickup['orderheaderid'] ?? ''}');
|
|
final int? pickupid = pickup['pickupid'] is int
|
|
? pickup['pickupid'] as int
|
|
: int.tryParse('${pickup['pickupid'] ?? ''}');
|
|
final int? userid = pickup['userid'] is int
|
|
? pickup['userid'] as int
|
|
: int.tryParse('${pickup['userid'] ?? ''}');
|
|
|
|
final String oid = (pickup['orderid'] ?? '').toString();
|
|
final String ostatus = (pickup['orderstatus'] ?? '').toString();
|
|
|
|
// Prefer pickuplat/long, fallback to droplat/lon
|
|
final String lat = (pickup['pickuplat'] ?? pickup['droplat'] ?? '')
|
|
.toString();
|
|
final String lon = (pickup['pickuplong'] ?? pickup['droplon'] ?? '')
|
|
.toString();
|
|
|
|
if (tenantid != null) await prefs.setInt(kTenantId, tenantid);
|
|
if (partnerid != null) await prefs.setInt(kPartnerId, partnerid);
|
|
if (locationid != null) await prefs.setInt(kLocationId, locationid);
|
|
if (orderheaderid != null)
|
|
await prefs.setInt(kOrderHeaderId, orderheaderid);
|
|
if (pickupid != null) await prefs.setInt(kPickupId, pickupid);
|
|
if (userid != null) await prefs.setInt(kUserId, userid);
|
|
if (oid.isNotEmpty) await prefs.setString(kOrderId, oid);
|
|
if (ostatus.isNotEmpty) await prefs.setString(kOrderStatus, ostatus);
|
|
if (lat.isNotEmpty) await prefs.setString(kLat, lat);
|
|
if (lon.isNotEmpty) await prefs.setString(kLng, lon);
|
|
|
|
// Update observables
|
|
orderId.value = oid;
|
|
orderStatus.value = ostatus;
|
|
tenantId.value = tenantid ?? 0;
|
|
partnerId.value = partnerid ?? 0;
|
|
locationId.value = locationid ?? 0;
|
|
orderHeaderId.value = orderheaderid ?? 0;
|
|
pickupId.value = pickupid ?? 0;
|
|
userId.value = userid ?? 0;
|
|
latitude.value = lat;
|
|
longitude.value = lon;
|
|
}
|
|
|
|
Future<void> loadFromPrefs() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
tenantId.value = prefs.getInt(kTenantId) ?? 0;
|
|
partnerId.value = prefs.getInt(kPartnerId) ?? 0;
|
|
locationId.value = prefs.getInt(kLocationId) ?? 0;
|
|
orderHeaderId.value = prefs.getInt(kOrderHeaderId) ?? 0;
|
|
pickupId.value = prefs.getInt(kPickupId) ?? 0;
|
|
userId.value = prefs.getInt(kUserId) ?? 0;
|
|
orderId.value = prefs.getString(kOrderId) ?? '';
|
|
orderStatus.value = prefs.getString(kOrderStatus) ?? '';
|
|
latitude.value = prefs.getString(kLat) ?? '';
|
|
longitude.value = prefs.getString(kLng) ?? '';
|
|
}
|
|
|
|
Future<void> clear() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove(kTenantId);
|
|
await prefs.remove(kPartnerId);
|
|
await prefs.remove(kLocationId);
|
|
await prefs.remove(kOrderHeaderId);
|
|
await prefs.remove(kPickupId);
|
|
await prefs.remove(kUserId);
|
|
await prefs.remove(kOrderId);
|
|
await prefs.remove(kOrderStatus);
|
|
await prefs.remove(kLat);
|
|
await prefs.remove(kLng);
|
|
|
|
orderId.value = '';
|
|
orderStatus.value = '';
|
|
tenantId.value = 0;
|
|
partnerId.value = 0;
|
|
locationId.value = 0;
|
|
orderHeaderId.value = 0;
|
|
pickupId.value = 0;
|
|
userId.value = 0;
|
|
latitude.value = '';
|
|
longitude.value = '';
|
|
}
|
|
}
|