remove connecticity plus web code, platform we do not need
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
c2e61f7cf7
commit
9e879d560f
|
@ -14,7 +14,7 @@ import 'package:flutter_local_notifications_linux/src/model/icon.dart';
|
|||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import '../../config.dart';
|
||||
import 'config.dart';
|
||||
|
||||
// NotificationsManager provides a wrapper around platform specific notifications logic.
|
||||
abstract class NotificationsManager {
|
||||
|
|
|
@ -10,8 +10,7 @@ import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_
|
|||
export 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart'
|
||||
show ConnectivityResult;
|
||||
|
||||
export 'src/connectivity_plus_linux.dart'
|
||||
if (dart.library.html) 'src/connectivity_plus_web.dart';
|
||||
export 'src/connectivity_plus_linux.dart';
|
||||
|
||||
/// Discover network connectivity configurations: Distinguish between WI-FI and cellular, check WI-FI status and more.
|
||||
class Connectivity {
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart';
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
|
||||
import 'web/network_information_api_connectivity_plugin.dart';
|
||||
import 'web/dart_html_connectivity_plugin.dart';
|
||||
|
||||
/// The web implementation of the ConnectivityPlatform of the Connectivity plugin.
|
||||
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 onnline 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
import 'dart:async';
|
||||
import 'dart:html' as html show window;
|
||||
|
||||
import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart';
|
||||
|
||||
import '../connectivity_plus_web.dart';
|
||||
|
||||
/// The web implementation of the ConnectivityPlatform of the Connectivity plugin.
|
||||
class DartHtmlConnectivityPlugin extends ConnectivityPlusWebPlugin {
|
||||
/// Checks the connection status of the device.
|
||||
@override
|
||||
Future<ConnectivityResult> checkConnectivity() async {
|
||||
return (html.window.navigator.onLine ?? false)
|
||||
? ConnectivityResult.wifi
|
||||
: ConnectivityResult.none;
|
||||
}
|
||||
|
||||
StreamController<ConnectivityResult>? _connectivityResult;
|
||||
|
||||
/// Returns a Stream of ConnectivityResults changes.
|
||||
@override
|
||||
Stream<ConnectivityResult> get onConnectivityChanged {
|
||||
if (_connectivityResult == null) {
|
||||
_connectivityResult = StreamController<ConnectivityResult>.broadcast();
|
||||
// Fallback to dart:html window.onOnline / window.onOffline
|
||||
html.window.onOnline.listen((event) {
|
||||
_connectivityResult!.add(ConnectivityResult.wifi);
|
||||
});
|
||||
html.window.onOffline.listen((event) {
|
||||
_connectivityResult!.add(ConnectivityResult.none);
|
||||
});
|
||||
}
|
||||
return _connectivityResult!.stream;
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
import 'dart:async';
|
||||
import 'dart:html' as html show window, NetworkInformation;
|
||||
import 'dart:js_util';
|
||||
|
||||
import 'package:connectivity_plus/src/web/utils/connectivity_result.dart';
|
||||
import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:js/js.dart';
|
||||
|
||||
import '../connectivity_plus_web.dart';
|
||||
|
||||
/// The web implementation of the ConnectivityPlatform of the Connectivity plugin.
|
||||
class NetworkInformationApiConnectivityPlugin
|
||||
extends ConnectivityPlusWebPlugin {
|
||||
final html.NetworkInformation _networkInformation;
|
||||
|
||||
/// A check to determine if this version of the plugin can be used.
|
||||
static bool isSupported() => html.window.navigator.connection != null;
|
||||
|
||||
/// The constructor of the plugin.
|
||||
NetworkInformationApiConnectivityPlugin()
|
||||
: this.withConnection(html.window.navigator.connection!);
|
||||
|
||||
/// Creates the plugin, with an override of the NetworkInformation object.
|
||||
@visibleForTesting
|
||||
NetworkInformationApiConnectivityPlugin.withConnection(
|
||||
html.NetworkInformation connection)
|
||||
: _networkInformation = connection;
|
||||
|
||||
/// Checks the connection status of the device.
|
||||
@override
|
||||
Future<ConnectivityResult> checkConnectivity() async {
|
||||
return networkInformationToConnectivityResult(_networkInformation);
|
||||
}
|
||||
|
||||
StreamController<ConnectivityResult>? _connectivityResultStreamController;
|
||||
late Stream<ConnectivityResult> _connectivityResultStream;
|
||||
|
||||
/// Returns a Stream of ConnectivityResults changes.
|
||||
@override
|
||||
Stream<ConnectivityResult> get onConnectivityChanged {
|
||||
// use fallback implementation if [_connectionSupported] is not availible
|
||||
if (_connectionSupported == null) {
|
||||
return _webPseudoStream();
|
||||
}
|
||||
if (_connectivityResultStreamController == null) {
|
||||
_connectivityResultStreamController =
|
||||
StreamController<ConnectivityResult>();
|
||||
setProperty(_networkInformation, 'onchange', allowInterop((_) {
|
||||
_connectivityResultStreamController!
|
||||
.add(networkInformationToConnectivityResult(_networkInformation));
|
||||
}));
|
||||
// ignore: todo
|
||||
// TODO: Implement the above with _networkInformation.onChange:
|
||||
// _networkInformation.onChange.listen((_) {
|
||||
// _connectivityResult
|
||||
// .add(networkInformationToConnectivityResult(_networkInformation));
|
||||
// });
|
||||
// Once we can detect when to *cancel* a subscription to the _networkInformation
|
||||
// onChange Stream upon hot restart.
|
||||
// https://github.com/dart-lang/sdk/issues/42679
|
||||
_connectivityResultStream =
|
||||
_connectivityResultStreamController!.stream.asBroadcastStream();
|
||||
}
|
||||
return _connectivityResultStream;
|
||||
}
|
||||
|
||||
/// stores the last fallback network state
|
||||
ConnectivityResult? _lastFallbackState;
|
||||
|
||||
/// periodically checks the current network state
|
||||
Stream<ConnectivityResult> _webPseudoStream() {
|
||||
final StreamController<ConnectivityResult> webStream =
|
||||
StreamController.broadcast();
|
||||
Timer.periodic(
|
||||
const Duration(milliseconds: 250),
|
||||
(timer) async {
|
||||
final result = await checkConnectivity();
|
||||
if (result != _lastFallbackState) {
|
||||
webStream.add(result);
|
||||
}
|
||||
},
|
||||
);
|
||||
return webStream.stream;
|
||||
}
|
||||
}
|
||||
|
||||
/// accesses the JS-native `navigator.connection`
|
||||
///
|
||||
/// ensures `navigator.connection.onchange` is availible
|
||||
@JS("navigator.connection")
|
||||
external get _connectionSupported;
|
|
@ -1,50 +0,0 @@
|
|||
import 'dart:html' as html show NetworkInformation;
|
||||
|
||||
import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart';
|
||||
|
||||
/// Converts an incoming NetworkInformation object into the correct ConnectivityResult.
|
||||
ConnectivityResult networkInformationToConnectivityResult(
|
||||
html.NetworkInformation info,
|
||||
) {
|
||||
if (info.downlink == 0 && info.rtt == 0) {
|
||||
return ConnectivityResult.none;
|
||||
}
|
||||
if (info.type != null) {
|
||||
return _typeToConnectivityResult(info.type!);
|
||||
}
|
||||
if (info.effectiveType != null) {
|
||||
return _effectiveTypeToConnectivityResult(info.effectiveType!);
|
||||
}
|
||||
return ConnectivityResult.none;
|
||||
}
|
||||
|
||||
ConnectivityResult _effectiveTypeToConnectivityResult(String effectiveType) {
|
||||
// Possible values:
|
||||
/*'2g'|'3g'|'4g'|'slow-2g'*/
|
||||
switch (effectiveType) {
|
||||
case 'slow-2g':
|
||||
case '2g':
|
||||
case '3g':
|
||||
case '4g':
|
||||
return ConnectivityResult.mobile;
|
||||
default:
|
||||
return ConnectivityResult.wifi;
|
||||
}
|
||||
}
|
||||
|
||||
ConnectivityResult _typeToConnectivityResult(String type) {
|
||||
// Possible values:
|
||||
/*'bluetooth'|'cellular'|'ethernet'|'mixed'|'none'|'other'|'unknown'|'wifi'|'wimax'*/
|
||||
switch (type) {
|
||||
case 'none':
|
||||
return ConnectivityResult.none;
|
||||
case 'bluetooth':
|
||||
case 'cellular':
|
||||
case 'mixed':
|
||||
case 'other':
|
||||
case 'unknown':
|
||||
case 'ethernet':
|
||||
default:
|
||||
return ConnectivityResult.mobile;
|
||||
}
|
||||
}
|
|
@ -21,9 +21,6 @@ flutter:
|
|||
dartPluginClass: ConnectivityPlusLinuxPlugin
|
||||
macos:
|
||||
pluginClass: ConnectivityPlugin
|
||||
web:
|
||||
pluginClass: ConnectivityPlusWebPlugin
|
||||
fileName: src/connectivity_plus_web.dart
|
||||
windows:
|
||||
pluginClass: ConnectivityPlusWindowsPlugin
|
||||
|
||||
|
|
Loading…
Reference in New Issue