diff --git a/lib/screens/map_tab.dart b/lib/screens/map_tab.dart index 785b01a..19838c0 100644 --- a/lib/screens/map_tab.dart +++ b/lib/screens/map_tab.dart @@ -193,7 +193,10 @@ class _MapTabState extends State with AutomaticKeepAliveClientMixin { // Start listening to compass events _compassStreamSubscription = compassStream.listen( (CompassEvent event) { - if (mounted && event.heading != null) { + // Double-check mounted status to prevent setState on disposed widget + if (!mounted || event.heading == null) return; + + try { setState(() { _compassHeading = event.heading; }); @@ -213,6 +216,9 @@ class _MapTabState extends State with AutomaticKeepAliveClientMixin { // Map not ready yet, ignore } } + } catch (e) { + // Widget disposed during setState, ignore + debugPrint('Compass tracking error: $e'); } }, );