fluttercommunity / fluttercommunity/plus_plugins

[Request]: Stream for Battery Level Changes

オープン
#3,733 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る
enhancement triage
主要言語
Dart
スター
1.9k
フォーク
1.3k
PR マージ指標
30日以内にマージされた PR はありません

説明

### 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 `BroadcastReceiver` for `Intent.ACTION_BATTERY_CHANGED`. This intent contains the EXTRA_LEVEL and EXTRA_SCALE to calculate the percentage immediately upon change.
* Web: The `BatteryManager` has a built-in event listener: `onlevelchange`.
* macOS: The system provides a system loop notification: `kIOPSPowerSourceHaveToUpdateNotification`

Something like:

```dart
// Current
Stream get onBatteryStateChanged;

// Proposed
Stream 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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、battery_plus のプラットフォーム実装と、既存の onBatteryStateChanged ストリームのエントリポイントを特定します。issue に記載されている iOS、Android、Web、macOS のバッテリーレベル API を比較し、そのうえで、新しいストリームがサポートされている各プラットフォームでポーリングを行わずにパーセンテージの変化をネイティブに発行することを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
dart, flutter
領域
mobile-dev
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。