fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.61k stars 974 forks source link

[Bug]: battery_plus_platform_interface misses enum case #2450

Closed felixwoestmann closed 11 months ago

felixwoestmann commented 11 months ago

Platform

Android 12

Plugin

battery_plus

Version

v5.0.1

Flutter SDK

v3.16.2

Steps to reproduce

Use the battery_plus plugin on an Android Emulator with a neutral charging state.

The battery_plus plugin after being updated to version v5.0.1 now contains the charging state "not_charging". see. https://github.com/fluttercommunity/plus_plugins/pull/2275

The corresponding platform interface (battery_plus_platform_interface) in its currrent version 2.0.0 is lacking this enum, leading to an ArgumentError.

File: utils.dart

BatteryState parseBatteryState(String state) {
  switch (state) {
    case 'full':
      return BatteryState.full;
    case 'charging':
      return BatteryState.charging;
    case 'discharging':
      return BatteryState.discharging;
    case 'connected_not_charging':
      return BatteryState.connectedNotCharging;
    case 'unknown':
      return BatteryState.unknown;
    default:
      throw ArgumentError('$state is not a valid BatteryState.');
  }
}

The initial commit contained the fix, this was however reverted by this commit: https://github.com/fluttercommunity/plus_plugins/commit/78f44bf41a7e8349240bacae2dd70598ba22e97a

Please release a hotfix.

Code Sample

No response

Logs

Invalid argument(s): not_charging is not a valid BatteryState.
I/flutter ( 3973): #0      parseBatteryState (package:battery_plus_platform_interface/src/utils.dart:17:7)
I/flutter ( 3973): #1      MethodChannelBattery.batteryState.<anonymous closure> (package:battery_plus_platform_interface/method_channel_battery_plus.dart:43:47)
I/flutter ( 3973): #2      _rootRunUnary (dart:async/zone.dart:1407:47)
I/flutter ( 3973): <asynchronous suspension>
I/flutter ( 3973): #3      BatteryIndicatorProvider._update (package:common/src/feature/battery/provider/battery_indicator_provider.dart:22:21)
I/flutter ( 3973): <asynchronous suspension>

Flutter Doctor

[✓] Flutter (Channel stable, 3.16.3, on macOS 14.0 23A344 darwin-arm64,
    locale en-DE)
    • Flutter version 3.16.3 on channel stable at
      /Users/felix/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0366e0a3f (7 days ago), 2023-12-05 19:46:39
      -0800
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version
    34.0.0)
    • Android SDK at /Users/felix/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    ! iOS 17.0 Simulator not installed; this may be necessary for iOS and
      macOS development.
      To download and install the platform, open Xcode, select Xcode >
      Settings > Platforms,
      and click the GET button for the required platform.

      For more information, please visit:
        https://developer.apple.com/documentation/xcode/installing-additi
        onal-simulator-runtimes
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google
      Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.85.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.78.0

[✓] Connected device (3 available)
    • Android SDK built for arm64 (mobile) • emulator-5554 •
      android-arm64  • Android 10 (API 29) (emulator)
    • macOS (desktop)                      • macos         • darwin-arm64
      • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)                         • chrome        •
      web-javascript • Google Chrome 120.0.6099.71

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

! Doctor found issues in 1 category.

Checklist before submitting a bug

vbuberen commented 11 months ago

Thanks for reporting. Indeed, there is an issue as not_charging wasn't a proper name that had to be changed to better explain what is the status about. I will release a fix shortly.

vbuberen commented 11 months ago

Released the fix for this issue in 5.0.2