fluttercommunity / fluttercommunity/plus_plugins

[Bug]: Linux bug on batteryState getter

Aperta Adatta ai principianti
#3,964 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug triage
Lingua principale
Dart
Stelle
1.9k
Fork
1.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Platform

Debian 12

### Plugin

battery_plus

### Version

7.1.1

### Flutter SDK

3.41.9

### Steps to reproduce

Just do a get on battery state.
I didn't test as I currently don't have time but here the code found here : https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/lib/src/battery_plus_linux.dart

```dart
/// Returns the current battery state.
@override
Future get batteryState {
final client = createClient();
return client
.connect()
.then((_) => client.displayDevice.state.toBatteryState())
.whenComplete(() => client.close);
}
```

The line `.whenComplete(() => client.close);` should be `.whenComplete(() => client.close());` as done juste before for the battery level :

```dart
/// Returns the current battery level in percent.
@override
Future get batteryLevel {
final client = createClient();
return client
.connect()
.then((_) => client.displayDevice.percentage.round())
.whenComplete(() => client.close());
}
```

The Dbus client behind is never closed, and each call create a new one. There is a risk to reach OS limits here.

### Code Sample

```dart

```

### Logs

```shell
No logs or errors to report
```

### Flutter Doctor

```shell
[✓] Flutter (Channel stable, 3.41.9, on Debian GNU/Linux 12 (bookworm) 6.1.0-52-amd64, locale en_US.UTF-8) [210ms]
• Flutter version 3.41.9 on channel stable at /data/develop/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 00b0c91f06 (4 months ago), 2026-04-29 10:03:19 -0700
• Engine revision 42d3d75a56
• Dart version 3.11.5
• DevTools version 2.54.2
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✗] Android toolchain - develop for Android devices [148ms]
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/to/linux-android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) [67ms]
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop [2.1s]
• Debian clang version 14.0.6
• cmake version 3.25.1
• ninja version 1.11.1
• pkg-config version 1.8.1
• GL_EXT_framebuffer_blit: no
• GL_EXT_texture_format_BGRA8888: no

[✓] Connected device (1 available) [202ms]
• Linux (desktop) • linux • linux-x64 • Debian GNU/Linux 12 (bookworm) 6.1.0-52-amd64

[✓] Network resources [637ms]
• All expected network resources are available.

! Doctor found issues in 2 categories.
```

### Checklist before submitting a bug

- [x] I searched issues in this repository and couldn't find such bug/problem
- [x] I Google'd a solution and I couldn't find it
- [x] I searched on StackOverflow for a solution and I couldn't find it
- [x] I read the README.md file of the plugin
- [x] I'm using the latest version of the plugin
- [x] All dependencies are up to date with `flutter pub upgrade`
- [x] I did a `flutter clean`
- [x] I tried running the example project

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Apri packages/battery_plus/battery_plus/lib/src/battery_plus_linux.dart e confronta il callback di pulizia di batteryState con l’implementazione di batteryLevel. Verifica che ogni richiesta batteryState chiuda il proprio client D-Bus al completamento, quindi esegui i controlli pertinenti del package o l’esempio per verificare il comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
dart, flutter
Ambito
desktop-dev
Tipo di issue
Bug
Difficoltà
1/5
Tempo stimato
Meno di un'ora
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
88/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.