Skip to content

Commit 07feeb3

Browse files
authored
[battery_plus] add "unknown" status (#61) (#139)
* [battery_plus] add "unknown" status (#61) * [battery_plus] bump versions and update changelogs
1 parent 13e97e0 commit 07feeb3

File tree

19 files changed

+60
-22
lines changed

19 files changed

+60
-22
lines changed

packages/battery_plus/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.0
2+
3+
- Added "unknown" battery state for batteryless systems.
4+
15
## 0.9.1
26

37
- Send initial battery status for Android

packages/battery_plus/android/src/main/java/dev/fluttercommunity/plus/battery/BatteryPlusPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ private static void publishBatteryStatus(final EventSink events, int status) {
121121
events.success("full");
122122
break;
123123
case BatteryManager.BATTERY_STATUS_DISCHARGING:
124+
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
124125
events.success("discharging");
125126
break;
127+
case BatteryManager.BATTERY_STATUS_UNKNOWN:
128+
events.success("unknown");
126129
default:
127130
events.error("UNAVAILABLE", "Charging status unavailable", null);
128131
break;

packages/battery_plus/ios/Classes/FLTBatteryPlusPlugin.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ - (void)sendBatteryStateEvent {
4848
if (!_eventSink) return;
4949
UIDeviceBatteryState state = [[UIDevice currentDevice] batteryState];
5050
switch (state) {
51+
case UIDeviceBatteryStateUnknown:
52+
_eventSink(@"unknown");
5153
case UIDeviceBatteryStateFull:
5254
_eventSink(@"full");
5355
case UIDeviceBatteryStateCharging:

packages/battery_plus/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: battery_plus
22
description: Flutter plugin for accessing information about the battery state(full, charging, discharging).
3-
version: 0.9.1
3+
version: 0.10.0
44
homepage: https://plus.fluttercommunity.dev/
55
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
66

@@ -25,11 +25,11 @@ dependencies:
2525
flutter:
2626
sdk: flutter
2727
meta: ^1.0.5
28-
battery_plus_platform_interface: ^0.2.0
29-
battery_plus_linux: ^0.1.0
30-
battery_plus_macos: ^0.1.0
31-
battery_plus_web: ^0.2.0
32-
battery_plus_windows: ^0.1.0
28+
battery_plus_platform_interface: ^0.3.0
29+
battery_plus_linux: ^0.2.0
30+
battery_plus_macos: ^0.2.0
31+
battery_plus_web: ^0.3.0
32+
battery_plus_windows: ^0.2.0
3333

3434
dev_dependencies:
3535
async: ^2.0.8
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0
2+
3+
- Added "unknown" battery state for batteryless systems.
4+
15
## 0.1.0
26

37
- Initial Linux support.

packages/battery_plus_linux/lib/src/battery_plus_linux_real.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import 'package:meta/meta.dart';
55

66
import 'upower_device.dart';
77

8-
// ### TODO: introduce an 'unknown' battery state for workstations?
9-
// https://github.com/fluttercommunity/plus_plugins/issues/61
108
extension _ToBatteryState on UPowerBatteryState {
119
BatteryState toBatteryState() {
1210
switch (this) {
1311
case UPowerBatteryState.charging:
1412
return BatteryState.charging;
1513
case UPowerBatteryState.discharging:
1614
return BatteryState.discharging;
17-
default:
15+
case UPowerBatteryState.fullyCharged:
1816
return BatteryState.full;
17+
default:
18+
return BatteryState.unknown;
1919
}
2020
}
2121
}

packages/battery_plus_linux/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: battery_plus_linux
22
description: Linux implementation of the battery_plus plugin
33
homepage: https://plus.fluttercommunity.dev/
44
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
5-
version: 0.1.0
5+
version: 0.2.0
66

77
environment:
88
sdk: ">=2.7.0 <3.0.0"
99
flutter: ">=1.20.0"
1010

1111
dependencies:
12-
battery_plus_platform_interface: ^0.2.0
12+
battery_plus_platform_interface: ^0.3.0
1313
dbus: ^0.1.0
1414
flutter:
1515
sdk: flutter
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0
2+
3+
- Added "unknown" battery state for batteryless systems.
4+
15
## 0.1.0
26

37
* Initial macOS release.

packages/battery_plus_macos/macos/Classes/BatteryPlusChargingHandler.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ class BatteryPlusChargingHandler: NSObject, FlutterStreamHandler {
7474

7575
// Returns nil when battery is discharging
7676
if let isCharging = (description[kIOPSPowerSourceStateKey] as? String) {
77-
if isCharging == kIOPSACPowerValue{
77+
if isCharging == kIOPSACPowerValue {
7878
return "charging"
79-
}else {
79+
} else if isCharging == kIOPSBatteryPowerValue {
8080
return "discharging"
81+
} else {
82+
return "unknown"
8183
}
8284
}
8385
return "UNAVAILABLE"

packages/battery_plus_macos/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: battery_plus_macos
22
description: An implementation for the macos platform of the Flutter `battery_plus` plugin.
33
homepage: https://plus.fluttercommunity.dev/
44
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
5-
version: 0.1.0
5+
version: 0.2.0
66

77
environment:
88
sdk: '>=2.6.0 <3.0.0'
99
flutter: '>=1.20.0'
1010

1111
dependencies:
12-
battery_plus_platform_interface: ^0.2.0
12+
battery_plus_platform_interface: ^0.3.0
1313
flutter:
1414
sdk: flutter
1515

0 commit comments

Comments
 (0)