refactor follow me mode state handling

This commit is contained in:
stopflock
2025-08-29 11:08:50 -05:00
parent 42c03eca7d
commit c4c1505253
7 changed files with 81 additions and 103 deletions
+13 -7
View File
@@ -21,7 +21,7 @@ import 'map/camera_refresh_controller.dart';
import 'map/gps_controller.dart';
import 'network_status_indicator.dart';
import '../dev_config.dart';
import '../screens/home_screen.dart' show FollowMeMode;
import '../app_state.dart' show FollowMeMode;
class MapView extends StatefulWidget {
final AnimatedMapController controller;
@@ -78,6 +78,18 @@ class MapViewState extends State<MapView> {
followMeMode: widget.followMeMode,
controller: _controller,
onLocationUpdated: () => setState(() {}),
getCurrentFollowMeMode: () {
// Use mounted check to avoid calling context when widget is disposed
if (mounted) {
try {
return context.read<AppState>().followMeMode;
} catch (e) {
debugPrint('[MapView] Could not read AppState, defaulting to off: $e');
return FollowMeMode.off;
}
}
return FollowMeMode.off;
},
);
// Fetch initial cameras
@@ -111,12 +123,6 @@ class MapViewState extends State<MapView> {
}
/// Expose static methods from MapPositionManager for external access
static Future<void> saveFollowMeMode(FollowMeMode mode) =>
MapPositionManager.saveFollowMeMode(mode);
static Future<FollowMeMode> loadFollowMeMode() =>
MapPositionManager.loadFollowMeMode();
static Future<void> clearStoredMapPosition() =>
MapPositionManager.clearStoredMapPosition();