[Bug]: Linux bug on batteryState getter

Open Beginner friendly
#3,964 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

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.

Description

bug triage
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

  /// Returns the current battery state.
  @override
  Future<BatteryState> 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 :

  /// Returns the current battery level in percent.
  @override
  Future<int> 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

Logs
No logs or errors to report
Flutter Doctor
[✓] 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
  • I searched issues in this repository and couldn't find such bug/problem
  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
Dominant language
Dart
Stars
1.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fluttercommunity/plus_plugins

All issues in fluttercommunity/plus_plugins

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.