diff --git a/lib/app_state.dart b/lib/app_state.dart index 4be3acc..4b805c2 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -175,22 +175,7 @@ class AppState extends ChangeNotifier { bool get suspectedLocationsLoading => _suspectedLocationState.isLoading; DateTime? get suspectedLocationsLastFetch => _suspectedLocationState.lastFetchTime; - // Track previous offline mode to detect changes - bool? _previousOfflineMode; - void _onStateChanged() { - // Check if offline mode changed - final currentOfflineMode = _settingsState.offlineMode; - if (_previousOfflineMode != null && _previousOfflineMode != currentOfflineMode) { - // Offline mode changed - if (currentOfflineMode) { - // Went offline - cancel any active navigation/search - debugPrint('[AppState] Went offline - canceling navigation'); - _navigationState.cancelNavigation(); - } - } - _previousOfflineMode = currentOfflineMode; - notifyListeners(); } @@ -199,9 +184,6 @@ class AppState extends ChangeNotifier { // Initialize all state modules await _settingsState.init(); - // Initialize offline mode tracking - _previousOfflineMode = _settingsState.offlineMode; - // Initialize changelog service await ChangelogService().init(); diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index fb7fec9..b3a92ce 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -385,14 +385,20 @@ class _HomeScreenState extends State with TickerProviderStateMixin { _sheetCoordinator.setEditSheetShown(false); } - // Auto-open navigation sheet when needed - simplified logic (only in dev mode) + // Auto-open navigation sheet when needed - only when online and in nav features mode if (kEnableNavigationFeatures) { - final shouldShowNavSheet = appState.isInSearchMode || appState.showingOverview; + final shouldShowNavSheet = !appState.offlineMode && (appState.isInSearchMode || appState.showingOverview); if (shouldShowNavSheet && !_sheetCoordinator.navigationSheetShown) { _sheetCoordinator.setNavigationSheetShown(true); WidgetsBinding.instance.addPostFrameCallback((_) => _openNavigationSheet()); - } else if (!shouldShowNavSheet) { + } else if (!shouldShowNavSheet && _sheetCoordinator.navigationSheetShown) { _sheetCoordinator.setNavigationSheetShown(false); + // When sheet should close (including going offline), clean up navigation state + if (appState.offlineMode) { + WidgetsBinding.instance.addPostFrameCallback((_) { + appState.cancelNavigation(); + }); + } } } @@ -491,8 +497,8 @@ class _HomeScreenState extends State with TickerProviderStateMixin { } }, ), - // Search bar (slides in when in search mode) - only online since search doesn't work offline - if (!appState.offlineMode && appState.isInSearchMode) + // Search bar (slides in when in search mode) + if (appState.isInSearchMode) Positioned( top: 0, left: 0, diff --git a/lib/widgets/navigation_sheet.dart b/lib/widgets/navigation_sheet.dart index 2cd2250..4912d50 100644 --- a/lib/widgets/navigation_sheet.dart +++ b/lib/widgets/navigation_sheet.dart @@ -101,32 +101,30 @@ class NavigationSheet extends StatelessWidget { address: provisionalAddress, ), const SizedBox(height: 16), - // Only show routing buttons if navigation features are enabled - if (enableNavigationFeatures(offlineMode: appState.offlineMode)) ...[ - Row( - children: [ - Expanded( - child: ElevatedButton.icon( - icon: const Icon(Icons.directions), - label: Text(LocalizationService.instance.t('navigation.routeTo')), - onPressed: () { - appState.startRoutePlanning(thisLocationIsStart: false); - }, - ), - ), - const SizedBox(width: 12), - Expanded( - child: ElevatedButton.icon( - icon: const Icon(Icons.my_location), - label: Text(LocalizationService.instance.t('navigation.routeFrom')), - onPressed: () { - appState.startRoutePlanning(thisLocationIsStart: true); - }, - ), - ), - ], - ), - ], + // Show routing buttons (sheet only opens when online, so always available) + Row( + children: [ + Expanded( + child: ElevatedButton.icon( + icon: const Icon(Icons.directions), + label: Text(LocalizationService.instance.t('navigation.routeTo')), + onPressed: () { + appState.startRoutePlanning(thisLocationIsStart: false); + }, + ), + ), + const SizedBox(width: 12), + Expanded( + child: ElevatedButton.icon( + icon: const Icon(Icons.my_location), + label: Text(LocalizationService.instance.t('navigation.routeFrom')), + onPressed: () { + appState.startRoutePlanning(thisLocationIsStart: true); + }, + ), + ), + ], + ), ], // SETTING SECOND POINT: Show both points and select button