monitorBatteryStatus method
Implementation
Future<Stream<ExtendedBatteryStatus>?> monitorBatteryStatus() async {
if (!isAndroid) {
debugPrint('monitorBatteryStatus: not supported on this platform');
return null;
}
if (_streamBatteryController != null) {
log('monitorBatteryStatus: already monitoring');
return _streamBatteryController!.stream;
}
_streamBatteryController = StreamController<ExtendedBatteryStatus>.broadcast();
_streamBatteryController!.onCancel = () {
log('monitorBatteryStatus: onCancel');
_streamBatteryController?.close();
_streamBatteryController = null;
};
final dynamic result = await _methodChannel.invokeMethod('monitorBatteryStatus');
debugPrint('monitorBatteryStatus: ${result.runtimeType}, $result');
return _streamBatteryController!.stream;
}