retry for location permission when follow-me enabled

This commit is contained in:
stopflock committed 2025-08-23 18:46:21 -05:00
1 parent d6625ccc23
commit f45279ecfe
2 files changed
+17 -3

No files matched your search

+9 -1
View File
@@ -19,6 +19,7 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> { class _HomeScreenState extends State<HomeScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
final GlobalKey<MapViewState> _mapViewKey = GlobalKey<MapViewState>();
final MapController _mapController = MapController(); final MapController _mapController = MapController();
bool _followMe = true; bool _followMe = true;
@@ -51,7 +52,13 @@ class _HomeScreenState extends State<HomeScreen> {
IconButton( IconButton(
tooltip: _followMe ? 'Disable follow‑me' : 'Enable follow‑me', tooltip: _followMe ? 'Disable follow‑me' : 'Enable follow‑me',
icon: Icon(_followMe ? Icons.gps_fixed : Icons.gps_off), 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( IconButton(
icon: const Icon(Icons.settings), icon: const Icon(Icons.settings),
@@ -62,6 +69,7 @@ class _HomeScreenState extends State<HomeScreen> {
body: Stack( body: Stack(
children: [ children: [
MapView( MapView(
key: _mapViewKey,
controller: _mapController, controller: _mapController,
followMe: _followMe, followMe: _followMe,
onUserGesture: () { onUserGesture: () {
+8 -2
View File
@@ -32,10 +32,10 @@ class MapView extends StatefulWidget {
final VoidCallback onUserGesture; final VoidCallback onUserGesture;
@override @override
State<MapView> createState() => _MapViewState(); State<MapView> createState() => MapViewState();
} }
class _MapViewState extends State<MapView> { class MapViewState extends State<MapView> {
late final MapController _controller; late final MapController _controller;
final Debouncer _cameraDebounce = Debouncer(kDebounceCameraRefresh); final Debouncer _cameraDebounce = Debouncer(kDebounceCameraRefresh);
final Debouncer _tileDebounce = Debouncer(const Duration(milliseconds: 150)); final Debouncer _tileDebounce = Debouncer(const Duration(milliseconds: 150));
@@ -84,6 +84,12 @@ class _MapViewState extends State<MapView> {
if (mounted) setState(() {}); if (mounted) setState(() {});
} }
/// Public method to retry location initialization (e.g., after permission granted)
void retryLocationInit() {
debugPrint('[MapView] Retrying location initialization');
_initLocation();
}
void _refreshCamerasFromProvider() { void _refreshCamerasFromProvider() {