plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Bug]: Battery save mode not available.

Open water-user opened this issue 2 years ago • 1 comments

Platform

10

Plugin

battery_plus

Version

^2.1.4

Flutter SDK

2.8.1

Steps to reproduce

Run the application. This crash occurs only on my Xiaomi Mi 9T Pro Screen Shot 2022-07-31 at 11 28 50

1659257037034

Code Sample

Battery().isInBatterySaveMode.then((isInSaveMode) {
      if (Platform.isIOS || !isInSaveMode || Prefs.isBatterySaverDetected) {
        return;
      } else {
        Future.delayed(Duration.zero, () => showBatterySaverDetectionDialog());
      }
    }).catchError((e) {
      print(e);
    });

Logs

No data.

Flutter Doctor

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (8 months ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1

water-user avatar Jul 31 '22 08:07 water-user

Well, if save mode is not available on the device, there's not much we can do :)

inInBatterySaveMode returns a bool, so we cannot return a different state (like unavailable).

Probably improving documentation and explaining that the method will throw is good enough.

Still, is good practice to catch all errors that can come from native platform calls just in case.

miquelbeltran avatar Jul 31 '22 13:07 miquelbeltran

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Dec 28 '22 00:12 github-actions[bot]

Can you please reopen the issue? This happens on a Huawei P30 Lite which has a battery save mode, so this shouldn't throw an exception.

JulianBissekkou avatar Mar 06 '23 16:03 JulianBissekkou