From a6ef1a408e056808ac8e59d7870ce063a12f873e Mon Sep 17 00:00:00 2001 From: Robert Ekl Date: Tue, 3 Mar 2026 22:57:26 -0600 Subject: [PATCH] Prevent duplicate GPS stream subscriptions on restart --- lib/services/gps_service.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/services/gps_service.dart b/lib/services/gps_service.dart index 1535a62..1c30249 100644 --- a/lib/services/gps_service.dart +++ b/lib/services/gps_service.dart @@ -161,6 +161,14 @@ class GpsService { Future startWatching() async { debugLog('[GPS] startWatching() called, current status: $_status'); + // Ensure only one active position stream subscription exists. + // startWatching() can be called multiple times (e.g. after permission flow). + if (_positionSubscription != null) { + debugLog('[GPS] Existing position subscription found, restarting watcher'); + await _positionSubscription?.cancel(); + _positionSubscription = null; + } + // Check if location services are enabled first (system-level setting) final serviceEnabled = await isLocationServiceEnabled(); debugLog('[GPS] Location services check: enabled=$serviceEnabled');