diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 4633078..2d86f59 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -19,6 +19,7 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { final GlobalKey _scaffoldKey = GlobalKey(); + final GlobalKey _mapViewKey = GlobalKey(); final MapController _mapController = MapController(); bool _followMe = true; @@ -51,7 +52,13 @@ class _HomeScreenState extends State { IconButton( tooltip: _followMe ? 'Disable follow‑me' : 'Enable follow‑me', icon: Icon(_followMe ? Icons.gps_fixed : Icons.gps_off), - onPressed: () => setState(() => _followMe = !_followMe), + onPressed: () { + setState(() => _followMe = !_followMe); + // If enabling follow-me, retry location init in case permission was granted + if (_followMe) { + _mapViewKey.currentState?.retryLocationInit(); + } + }, ), IconButton( icon: const Icon(Icons.settings), @@ -62,6 +69,7 @@ class _HomeScreenState extends State { body: Stack( children: [ MapView( + key: _mapViewKey, controller: _mapController, followMe: _followMe, onUserGesture: () { diff --git a/lib/widgets/map_view.dart b/lib/widgets/map_view.dart index 508aa1a..c04baa5 100644 --- a/lib/widgets/map_view.dart +++ b/lib/widgets/map_view.dart @@ -32,10 +32,10 @@ class MapView extends StatefulWidget { final VoidCallback onUserGesture; @override - State createState() => _MapViewState(); + State createState() => MapViewState(); } -class _MapViewState extends State { +class MapViewState extends State { late final MapController _controller; final Debouncer _cameraDebounce = Debouncer(kDebounceCameraRefresh); final Debouncer _tileDebounce = Debouncer(const Duration(milliseconds: 150)); @@ -84,6 +84,12 @@ class _MapViewState extends State { if (mounted) setState(() {}); } + /// Public method to retry location initialization (e.g., after permission granted) + void retryLocationInit() { + debugPrint('[MapView] Retrying location initialization'); + _initLocation(); + } + void _refreshCamerasFromProvider() {