calculateAdaptiveSettings static method
Calculates optimal settings based on current conditions.
Implementation
static Future<AdaptiveSettings> calculateAdaptiveSettings() async {
final config = _adaptiveConfig ?? AdaptiveTrackingConfig.balanced;
final state = await LocusLifecycle.getState();
final result = await LocusChannels.methods.invokeMethod('getPowerState');
final power = result is Map
? PowerState.fromMap(Map<String, dynamic>.from(result))
: PowerState.unknown;
final location = state.location;
final isInGeofence = await LocusLifecycle.isInActiveGeofence();
// Track stationary time for stationaryDelay feature
if (state.isMoving) {
_stationarySince = null;
_lastKnownMovingState = true;
} else if (_lastKnownMovingState) {
// Just became stationary
_stationarySince = DateTime.now();
_lastKnownMovingState = false;
}
Duration? timeSinceStationary;
if (_stationarySince != null) {
timeSinceStationary = DateTime.now().difference(_stationarySince!);
}
return config.calculateSettings(
speedMps: location?.coords.speed ?? 0,
batteryPercent: power.batteryLevel,
isCharging: power.isCharging,
isMoving: state.isMoving,
activity: location?.activity?.type,
isInGeofence: isInGeofence,
timeSinceStationary: timeSinceStationary,
);
}