Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ class ConnectivityPlusWebPlugin extends ConnectivityPlatform {
/// Factory method that initializes the connectivity plugin platform with an instance
/// of the plugin for the web.
static void registerWith(Registrar registrar) {
// Since the `NetworkInformationApi` is currently an experimental API and
// does not provide a reliable way to check a connectivity change
// from an online state to an offline state,
// its implementation is disabled for now.
// See also: https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
//
// TODO: use `NetworkInformationApiConnectivityPlugin.isSupported()` when it becomes a stable DOM API.
// const isSupported = false;
// if (isSupported) {
// ConnectivityPlatform.instance = NetworkInformationApiConnectivityPlugin();
// } else {
// ConnectivityPlatform.instance = DartHtmlConnectivityPlugin();
// }

ConnectivityPlatform.instance = DartHtmlConnectivityPlugin();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'dart:async';
import 'dart:html' as html show window;
// Used in web: 0.3.0, deprecated later.
// Remove when increasing min web version.
// ignore: deprecated_member_use
import 'package:web/helpers.dart';
import 'package:web/web.dart';

import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart';

Expand All @@ -10,7 +14,7 @@ class DartHtmlConnectivityPlugin extends ConnectivityPlusWebPlugin {
/// Checks the connection status of the device.
@override
Future<ConnectivityResult> checkConnectivity() async {
return (html.window.navigator.onLine ?? false)
return (window.navigator.onLine)
? ConnectivityResult.wifi
: ConnectivityResult.none;
}
Expand All @@ -22,11 +26,10 @@ class DartHtmlConnectivityPlugin extends ConnectivityPlusWebPlugin {
Stream<ConnectivityResult> get onConnectivityChanged {
if (_connectivityResult == null) {
_connectivityResult = StreamController<ConnectivityResult>.broadcast();
// Fallback to dart:html window.onOnline / window.onOffline
html.window.onOnline.listen((event) {
const EventStreamProvider<Event>('online').forTarget(window).listen((_) {
_connectivityResult!.add(ConnectivityResult.wifi);
});
html.window.onOffline.listen((event) {
const EventStreamProvider<Event>('offline').forTarget(window).listen((_) {
_connectivityResult!.add(ConnectivityResult.none);
});
}
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions packages/connectivity_plus/connectivity_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
issue_tracker: https://github.com/fluttercommunity/plus_plugins/labels/connectivity_plus

environment:
sdk: ">=2.18.0 <4.0.0"
sdk: ">=3.2.0 <4.0.0"
flutter: ">=3.3.0"

flutter:
Expand All @@ -33,7 +33,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
connectivity_plus_platform_interface: ^1.2.4
js: ^0.6.4
web: '>=0.3.0 <=0.6.0'
meta: ^1.8.0
nm: ^0.5.0

Expand Down