mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: Improve compass event handling to prevent errors on disposed widget
This commit is contained in:
@@ -193,7 +193,10 @@ class _MapTabState extends State<MapTab> 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<MapTab> with AutomaticKeepAliveClientMixin {
|
||||
// Map not ready yet, ignore
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Widget disposed during setState, ignore
|
||||
debugPrint('Compass tracking error: $e');
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user