mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-02-12 16:52:51 +00:00
Got rid of some redundant / can never happen type of if statements
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -385,14 +385,20 @@ class _HomeScreenState extends State<HomeScreen> 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<HomeScreen> 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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user