mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-12 08:50:30 +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
|
// Start listening to compass events
|
||||||
_compassStreamSubscription = compassStream.listen(
|
_compassStreamSubscription = compassStream.listen(
|
||||||
(CompassEvent event) {
|
(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(() {
|
setState(() {
|
||||||
_compassHeading = event.heading;
|
_compassHeading = event.heading;
|
||||||
});
|
});
|
||||||
@@ -213,6 +216,9 @@ class _MapTabState extends State<MapTab> with AutomaticKeepAliveClientMixin {
|
|||||||
// Map not ready yet, ignore
|
// Map not ready yet, ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Widget disposed during setState, ignore
|
||||||
|
debugPrint('Compass tracking error: $e');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user