Fixed In Progress ISR not reflecting on IT Staff Pulse Dashboard Status Pill

Made the Location Tracking more persistent
This commit is contained in:
2026-03-11 07:43:14 +08:00
parent 24ecca9f06
commit 21e6d68910
6 changed files with 78 additions and 7 deletions
+23 -1
View File
@@ -105,7 +105,27 @@ Future<void> onBackgroundServiceStart(ServiceInstance service) async {
// Send initial location immediately on service start.
await _sendLocationUpdate();
// Periodic 15-minute timer for location updates.
// Maintain a subscription to the position stream so the service remains
// active when the device is moving. We still keep a periodic timer as a
// backup so that updates fire even when stationary.
StreamSubscription<Position>? positionSub;
try {
positionSub =
Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 0,
),
).listen((pos) {
debugPrint('[BgLoc] Stream position: $pos');
_sendLocationUpdate();
});
} catch (e) {
debugPrint('[BgLoc] Position stream failed: $e');
}
// Periodic 15-minute timer for location updates (backup when stream is
// paused by Doze).
Timer.periodic(_updateInterval, (_) async {
debugPrint('[BgLoc] Periodic update triggered');
await _sendLocationUpdate();
@@ -114,6 +134,7 @@ Future<void> onBackgroundServiceStart(ServiceInstance service) async {
// Listen for stop command from the foreground.
service.on('stop').listen((_) {
debugPrint('[BgLoc] Stop command received');
positionSub?.cancel();
service.stopSelf();
});
}
@@ -160,6 +181,7 @@ Future<void> initBackgroundLocationService() async {
}
/// Start the background location service.
Future<void> startBackgroundLocationUpdates() async {
if (kIsWeb) return;