-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Plugin
battery_plus
Use case
At the moment, there is no option to track changes in battery level or other aspects. However, for many apps, it would be quite reasonable to react to changes in battery level or any other, by displaying a snackbar message or sending analytics data.
iOS provides support for this functionality:
Documentation
NotificationCenter.default
.publisher(for: UIDevice.batteryLevelDidChangeNotification)
.sink(receiveValue: { _ in self.onBatteryLevelChanged() })Android also supports monitoring battery level changes:
Documentation
applicationContext?.registerReceiver(
this,
IntentFilter().apply {
addAction(Intent.ACTION_BATTERY_CHANGED)
}
)I’m not entirely sure about other platforms, but I would expect similar functionality to be available.
Proposal
Introduce class with full info and related stream to listen:
class BatteryInfo {
final double level;
final bool isLow;
final bool isInBatterySaveMode;
final BatteryState state;
}
battery.onBatteryInfoChanged.listen((BatteryInfo info) {
// Do something with new info
});