Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump web from 0.5.1 to 1.0.0 in /packages/battery_plus/battery_plus #3103

Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 3 additions & 21 deletions packages/battery_plus/battery_plus/lib/src/battery_plus_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:js_interop';

import 'package:battery_plus_platform_interface/battery_plus_platform_interface.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:web/web.dart' as web;
import 'package:web/web.dart';

/// The web implementation of the BatteryPlatform of the Battery plugin.
///
Expand All @@ -18,7 +18,7 @@ class BatteryPlusWebPlugin extends BatteryPlatform {
/// Return [BatteryManager] if the BatteryManager API is supported by the User Agent.
Future<BatteryManager?> _getBatteryManager() async {
try {
return await web.window.navigator.getBattery()?.toDart;
return await window.navigator.getBattery().toDart;
} on NoSuchMethodError catch (_) {
// BatteryManager API is not supported this User Agent.
return null;
Expand Down Expand Up @@ -80,7 +80,7 @@ class BatteryPlusWebPlugin extends BatteryPlatform {
_checkBatteryChargingState(batteryManager.charging),
);

batteryManager.onchargingchange = (web.Event _) {
batteryManager.onchargingchange = (Event _) {
_batteryChangeStreamController?.add(
_checkBatteryChargingState(batteryManager.charging),
);
Expand All @@ -105,21 +105,3 @@ class BatteryPlusWebPlugin extends BatteryPlatform {
}
}
}

extension on web.Navigator {
/// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery
external JSPromise<BatteryManager>? getBattery();
}

/// BatteryManager API
/// https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager
extension type BatteryManager(JSObject _) implements JSObject {
/// https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager/level
external double get level;

/// https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager/charging
external bool get charging;

/// https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager/chargingchange_event
external set onchargingchange(JSFunction fn);
}
2 changes: 1 addition & 1 deletion packages/battery_plus/battery_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
battery_plus_platform_interface: ^2.0.1
meta: ^1.8.0
upower: ^0.7.0
web: ^0.5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we doing the range ">=0.5.1 <2.0.0" like the packages repo did for these?

flutter/packages#7202

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, switching to ^1.0.0 is preferable since we want to use the newly available APIs changes in the web package, i.e. getBattery()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We kept the custom extensions in those packages in order to support both 0.5.0 and 1.0.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I thought we agreed to remove the custom extensions since 1.0.0 already provide those types.

Personally, I am more keen to use 1.0.0 directly and remove the extensions, and only keep the range in cases where no extensions are involved (e.g. with other plugins like device_info_plus).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My vote is for going ^1.0.0 here and in the share_plus.

web: ^1.0.0

dev_dependencies:
flutter_test:
Expand Down
Loading