Skip to content

[Request]: Support tracking all battery aspects #3446

@feduke-nukem

Description

@feduke-nukem

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
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions