Feature: Keep screen on while using app. Initial working.

This commit is contained in:
Ryan Brown
2026-05-09 22:02:36 +00:00
parent 5b55171080
commit 329974a8f0
6 changed files with 65 additions and 2 deletions
+18
View File
@@ -3,6 +3,7 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_animations/flutter_map_animations.dart';
import 'package:latlong2/latlong.dart';
import 'package:provider/provider.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import '../app_state.dart' show AppState, FollowMeMode;
import '../services/offline_area_service.dart';
@@ -84,7 +85,20 @@ class MapViewState extends State<MapView> {
// Track active pointers to suppress follow-me animations during touch
int _activePointers = 0;
bool _isWakelockEnabled = false;
void _updateWakelock(bool shouldBeAwake) {
if (_isWakelockEnabled != shouldBeAwake) {
_isWakelockEnabled = shouldBeAwake;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (shouldBeAwake) {
WakelockPlus.enable();
} else {
WakelockPlus.disable();
}
});
}
}
@override
void initState() {
@@ -213,6 +227,7 @@ class MapViewState extends State<MapView> {
_nodeController.dispose();
_tileManager.dispose();
_gpsController.dispose();
WakelockPlus.disable();
// PrefetchAreaService no longer used - replaced with NodeDataManager
super.dispose();
}
@@ -278,6 +293,9 @@ class MapViewState extends State<MapView> {
final session = appState.session;
final editSession = appState.editSession;
// Call the safe tracker using appState instead
_updateWakelock(appState.keepScreenAwake);
// Check if enabled profiles changed and refresh nodes if needed
_nodeController.checkAndHandleProfileChanges(
currentEnabledProfiles: appState.enabledProfiles,