fluttercommunity / fluttercommunity/plus_plugins

[Bug]: Linux bug on batteryState getter

Open Beginner friendly
#3,964 0 comments 0 reactions 0 assignees View on GitHub
bug triage
Dominant language
Dart
Stars
1.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Research direction

Open packages/battery_plus/battery_plus/lib/src/battery_plus_linux.dart and compare the batteryState cleanup callback with the batteryLevel implementation. Confirm that each batteryState request closes its D-Bus client when complete, then run the package's relevant checks or example to verify the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
desktop-dev
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.