Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update to null-safety
  • Loading branch information
bparrishMines committed Dec 23, 2020
commit ba04fba6bfe31afc1a9275824f36b1f3b86c8a5d
4 changes: 4 additions & 0 deletions packages/battery/battery_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety

* Migrate to null safety.

## 1.0.1

- Update Flutter SDK constraint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@ import '../battery_platform_interface.dart';
class MethodChannelBattery extends BatteryPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
MethodChannel channel = MethodChannel('plugins.flutter.io/battery');
final MethodChannel channel = MethodChannel('plugins.flutter.io/battery');

/// The event channel used to interact with the native platform.
@visibleForTesting
EventChannel eventChannel = EventChannel('plugins.flutter.io/charging');
final EventChannel eventChannel = EventChannel('plugins.flutter.io/charging');

/// Method channel for getting battery level.
Future<int> batteryLevel() async {
return (await channel.invokeMethod('getBatteryLevel')).toInt();
}

/// Stream variable for storing battery state.
Stream<BatteryState> _onBatteryStateChanged;
late final Stream<BatteryState> _onBatteryStateChanged;

/// Event channel for getting battery change state.
Stream<BatteryState> onBatteryStateChanged() {
if (_onBatteryStateChanged == null) {
_onBatteryStateChanged = eventChannel
.receiveBroadcastStream()
.map((dynamic event) => _parseBatteryState(event));
}
_onBatteryStateChanged = eventChannel
.receiveBroadcastStream()
.map((dynamic event) => _parseBatteryState(event));

return _onBatteryStateChanged;
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/battery/battery_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ description: A common platform interface for the battery plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/battery
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.1
version: 2.0.0-nullsafety

dependencies:
flutter:
sdk: flutter
meta: ^1.1.8
plugin_platform_interface: ^1.0.2
meta: ^1.3.0-nullsafety.6
plugin_platform_interface: ^1.1.0-nullsafety.1

dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^4.1.1
pedantic: ^1.8.0
mockito: ^5.0.0-nullsafety.0
pedantic: ^1.10.0-nullsafety.3

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.9.1+hotfix.4"
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import 'package:battery_platform_interface/method_channel/method_channel_battery
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

group("$MethodChannelBattery", () {
MethodChannelBattery methodChannelBattery;
group('$MethodChannelBattery', () {
late MethodChannelBattery methodChannelBattery;

setUp(() async {
methodChannelBattery = MethodChannelBattery();
Expand All @@ -32,7 +32,7 @@ void main() {
.setMockMethodCallHandler((MethodCall methodCall) async {
switch (methodCall.method) {
case 'listen':
await ServicesBinding.instance.defaultBinaryMessenger
await ServicesBinding.instance!.defaultBinaryMessenger
.handlePlatformMessage(
methodChannelBattery.eventChannel.name,
methodChannelBattery.eventChannel.codec
Expand All @@ -48,13 +48,13 @@ void main() {
});

/// Test for batetry level call.
test("getBatteryLevel", () async {
test('getBatteryLevel', () async {
final int result = await methodChannelBattery.batteryLevel();
expect(result, 90);
});

/// Test for battery changed state call.
test("onBatteryChanged", () async {
test('onBatteryChanged', () async {
final BatteryState result =
await methodChannelBattery.onBatteryStateChanged().first;
expect(result, BatteryState.full);
Expand Down