fluttercommunity / fluttercommunity/plus_plugins

[Request]: Stream for Battery Level Changes

Abierto
#3,733 1 comentario 1 reacción 0 asignados Ver en GitHub
enhancement triage
Lenguaje dominante
Dart
Estrellas
1.9k
Forks
1.3k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### 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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza localizando las implementaciones de plataforma de battery_plus y el punto de entrada existente del stream onBatteryStateChanged. Compara las APIs del nivel de batería de iOS, Android, Web y macOS mencionadas en la issue, y verifica después que el nuevo stream emita nativamente los cambios porcentuales en cada plataforma compatible sin realizar polling.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
dart, flutter
Área
mobile-dev
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.