From b899c792a660ae34a7a2ee7b43e20fe9d22ef53e Mon Sep 17 00:00:00 2001 From: Janez T Date: Tue, 28 Oct 2025 21:21:03 +0100 Subject: [PATCH] feat: Update location pointer colors to use theme color for better consistency --- lib/screens/map_tab.dart | 20 +++++++++++++++----- lib/screens/mcp.json | 10 ++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 lib/screens/mcp.json diff --git a/lib/screens/map_tab.dart b/lib/screens/map_tab.dart index afa00e3..39bef91 100644 --- a/lib/screens/map_tab.dart +++ b/lib/screens/map_tab.dart @@ -75,6 +75,7 @@ class _MapTabState extends State with AutomaticKeepAliveClientMixin { bool _backgroundTrackingEnabled = false; // Toggle for background tracking StreamSubscription? _compassStreamSubscription; final BackgroundLocationService _backgroundLocationService = BackgroundLocationService(); + bool _isDisposing = false; // Flag to prevent updates during disposal // MBTiles layers List _mbtilesLayers = []; @@ -195,8 +196,8 @@ class _MapTabState extends State with AutomaticKeepAliveClientMixin { // Start listening to compass events _compassStreamSubscription = compassStream.listen( (CompassEvent event) { - // Double-check mounted status to prevent setState on disposed widget - if (!mounted || event.heading == null) return; + // Check if widget is disposing, mounted, and event has valid heading + if (_isDisposing || !mounted || event.heading == null) return; try { setState(() { @@ -205,7 +206,7 @@ class _MapTabState extends State with AutomaticKeepAliveClientMixin { // Rotate map if rotation mode is enabled and we have compass heading // Only rotate if map is ready - if (_rotateMarkerWithHeading && event.heading != null && _isMapReady) { + if (_rotateMarkerWithHeading && event.heading != null && _isMapReady && !_isDisposing) { try { // Use moveAndRotate to set absolute rotation final camera = _mapController.camera; @@ -220,7 +221,9 @@ class _MapTabState extends State with AutomaticKeepAliveClientMixin { } } catch (e) { // Widget disposed during setState, ignore - debugPrint('Compass tracking error: $e'); + if (!_isDisposing) { + debugPrint('Compass tracking error: $e'); + } } }, ); @@ -415,12 +418,19 @@ class _MapTabState extends State with AutomaticKeepAliveClientMixin { @override void dispose() { + // Set flag immediately to prevent any async callbacks from firing + _isDisposing = true; + + // Cancel compass subscription first to stop new events + _compassStreamSubscription?.cancel(); + _compassStreamSubscription = null; + // Save map position before disposing _saveMapPosition(); final mapProvider = context.read(); mapProvider.removeListener(_handleMapNavigation); - _compassStreamSubscription?.cancel(); + // DO NOT stop location tracking - it's managed by AppProvider // Just clear the map-specific callback _locationService.onPositionUpdate = null; diff --git a/lib/screens/mcp.json b/lib/screens/mcp.json new file mode 100644 index 0000000..a3019b9 --- /dev/null +++ b/lib/screens/mcp.json @@ -0,0 +1,10 @@ +{ + "mcpServers": { + "dart": { + "command": "dart", + "args": [ + "mcp-server" + ] + } + } +} \ No newline at end of file