PowerState.fromMap constructor
- JsonMap map
Creates from a map.
Implementation
factory PowerState.fromMap(JsonMap map) {
return PowerState(
batteryLevel: (map['batteryLevel'] as num?)?.toInt() ?? 50,
isCharging: map['isCharging'] as bool? ?? false,
chargingType: ChargingType.values.firstWhere(
(e) => e.name == map['chargingType'],
orElse: () => ChargingType.none,
),
isPowerSaveMode: map['isPowerSaveMode'] as bool? ?? false,
isDozeMode: map['isDozeMode'] as bool? ?? false,
isBatteryOptimizationExempt:
map['isBatteryOptimizationExempt'] as bool? ?? false,
timeToFullCharge: map['timeToFullChargeSeconds'] != null
? Duration(seconds: (map['timeToFullChargeSeconds'] as num).toInt())
: null,
timeRemaining: map['timeRemainingSeconds'] != null
? Duration(seconds: (map['timeRemainingSeconds'] as num).toInt())
: null,
);
}