getBattery method
Retrieves the current battery state, including level, temperature, and charging status.
Implementation
Future<BatteryState> getBattery() async {
try {
final result = await _methodChannel.invokeMapMethod<String, dynamic>(
'getBattery',
);
if (result == null) {
throw Exception("Failed to retrieve battery state.");
}
return BatteryState.fromMap(result);
} catch (e) {
throw Exception("Error fetching battery state: $e");
}
}