Tracks battery status.
Depends on battery_plus.
dependencies:
flutter_use_battery: ^0.0.2
class Sample extends HookWidget {
@override
Widget build(BuildContext context) {
final battery = useBattery();
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text("-- Battery --"),
Text("fetched: ${battery.fetched}"),
Text("batteryState: ${battery.batteryState}"),
Text("level: ${battery.batteryLevel}"),
Text("isInBatterySaveMode: ${battery.isInBatterySaveMode}"),
],
),
),
);
}
}
fetched
: bool
- whether battery state is fetched;batteryLevel
: int
- representing the system's battery charge level to a value between 0 and 100.isInBatterySaveMode
: bool
- check if device is on battery save mode.batteryState
: BatteryState
- battery state changes.full
- The battery is completely full of energy.charging
-The battery is currently storing energy.discharging
- The battery is currently losing energy.unknown
- The state of the battery is unknown.