[Request]: Stream for Battery Level Changes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Domain
- mobile-dev
Research direction
Start by locating the battery_plus platform implementations and the existing onBatteryStateChanged stream entry point. Compare the iOS, Android, Web, and macOS battery-level APIs named in the issue, then verify that the new stream emits percentage changes natively on each supported platform without polling.
Written by the indexing model from the issue text.
Description
Plugin
battery_plus
Use case
Currently, battery_plus only provides a Future for batteryLevel and a Stream for batteryState. To track level changes, developers are forced to use Timer.periodic to poll the getter, which is inefficient and not reactive.
Proposal
I would like to request a new stream: Stream onBatteryLevelChanged.
Platforms support this natively, so we should not need to rely on polling.
- iOS: We can observe
UIDevice.batteryLevelDidChangeNotification. Note: Apple documentation states this notification is sent no more frequently than once per minute, which is acceptable for most use cases. - Android: We can register a
BroadcastReceiverforIntent.ACTION_BATTERY_CHANGED. This intent contains the EXTRA_LEVEL and EXTRA_SCALE to calculate the percentage immediately upon change. - Web: The
BatteryManagerhas a built-in event listener:onlevelchange. - macOS: The system provides a system loop notification:
kIOPSPowerSourceHaveToUpdateNotification
Something like:
// Current
Stream<BatteryState> get onBatteryStateChanged;
// Proposed
Stream<int> get onBatteryLevelChanged;
Additional Context
- This issue streamlines the battery level, but a stream to listen to all battery aspects would the preferrable solution. See #3446
- Dominant language
- Dart
- Stars
- 1.9k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fluttercommunity/plus_plugins
-
bug triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
fluttercommunity/plus_plugins#3979 ·
Maintainers usually reply within 1 day
-
bug triage
Difficulty 1/5 Under an hour Newbie friendliness 88/100
fluttercommunity/plus_plugins#3964 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
fluttercommunity/plus_plugins#3943 ·
Maintainers usually reply within 1 day
-
enhancement triage
Difficulty 4/5 3-5 days Newbie friendliness 55/100
fluttercommunity/plus_plugins#3976 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
fluttercommunity/plus_plugins#3974 ·
Maintainers usually reply within 1 day
All issues in fluttercommunity/plus_plugins
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
area-clientside-dartpad
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
dart-lang/dart-pad#3938 · 1 comment ·
Maintainers usually reply within 1 day
-
package:dart_mcp_server
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
dart-lang/ai#692 · 1 comment ·
Maintainers usually reply within 1 day
-
waiting for response
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
flutter/flutter#193333 · 1 comment ·
Maintainers usually reply within 1 day
-
general
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
ScottKirvan/QuKi-Notes#444 ·
Maintainers usually reply within 22 days