parseBatteryLevel static method

BatteryChargingState parseBatteryLevel(
  1. int batteryLevel
)

The BatteryChargingState for a battery level percentage (0-100).

0-10 is critical, 11-20 low, 21-90 normal, 91-100 full, and anything above 100 unknown.

Implementation

static BatteryChargingState parseBatteryLevel(int batteryLevel) => switch (batteryLevel) {
  <= 10 => BatteryChargingState.critical,
  > 10 && <= 20 => BatteryChargingState.low,
  > 20 && <= 90 => BatteryChargingState.normal,
  > 90 && <= 100 => BatteryChargingState.full,
  _ => BatteryChargingState.unknown,
};