Skip to content

[Bug]: Linux bug on batteryState getter #3964

Description

@geosebas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions