BatteryStats class

Statistics about battery usage during location tracking.

Use these metrics to understand how your tracking configuration affects battery consumption and to identify optimization opportunities.

Example:

final stats = await Locus.getBatteryStats();
print('GPS active: ${stats.gpsOnTimePercent.toStringAsFixed(1)}%');
print('Drain estimate: ${stats.estimatedDrainPerHour}%/hr');

Constructors

BatteryStats({double gpsOnTimePercent = 0, int locationUpdatesCount = 0, int syncRequestsCount = 0, double averageAccuracyMeters = 0, int trackingDurationMinutes = 0, double? estimatedDrainPercent, OptimizationLevel optimizationLevel = OptimizationLevel.none, Map<String, Duration> timeByState = const {}, int? currentBatteryLevel, bool? isCharging, int accuracyDowngradeCount = 0, int gpsDisabledCount = 0})
Creates battery statistics.
const
BatteryStats.empty()
Creates an empty stats object.
const
BatteryStats.fromMap(JsonMap map)
Creates from a map.
factory

Properties

accuracyDowngradeCount int
Number of accuracy downgrades due to battery saving.
final
averageAccuracyMeters double
Average horizontal accuracy of received locations in meters.
final
averageUpdateIntervalSeconds double?
Average time between location updates in seconds.
no setter
currentBatteryLevel int?
Current battery level (0-100) if available.
final
estimatedDrainPercent double?
Estimated battery drain percentage since tracking started.
final
estimatedDrainPerHour double?
Estimated drain per hour based on current patterns.
no setter
gpsDisabledCount int
Number of times GPS was disabled due to stationary detection.
final
gpsOnTimePercent double
Percentage of tracking time GPS was actively acquiring locations.
final
hashCode int
The hash code for this object.
no setterinherited
isCharging bool?
Whether the device is currently charging.
final
locationUpdatesCount int
Total number of location updates received since tracking started.
final
optimizationLevel OptimizationLevel
Current optimization level being applied.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
syncRequestsCount int
Number of HTTP sync requests made.
final
timeByState Map<String, Duration>
Time spent in each motion state.
final
trackingDurationMinutes int
Total tracking duration in minutes.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMap() JsonMap
Converts to a JSON-serializable map.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited