Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 442852f

Browse files
committed
Return null in unsupported browsers.
1 parent de4e9dc commit 442852f

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

packages/connectivity/connectivity_web/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ On desktop browsers, the API only returns a very broad set of connectivity statu
3333

3434
Other than the approximate "downlink" speed, and due to security and privacy concerns, this Web API will not provide any specific information about the actual network your users' device is connected to, like the SSID on a Wi-Fi, or the MAC address of their device, in any web platform (mobile or desktop).
3535

36+
### `null` connectivity results
37+
38+
Because of the limitations above, unsupported browsers will return `null` connectivity results, both on the `checkConnectivity` call, and the `onConnectivityChanged` stream.
39+
3640
## Contributions and Testing
3741

3842
Tests are a crucial to contributions to this package. All new contributions should be reasonably tested.

packages/connectivity/connectivity_web/lib/connectivity_web.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class ConnectivityPlugin extends ConnectivityPlatform {
3333
@override
3434
Future<ConnectivityResult> checkConnectivity() async {
3535
if (!_networkInformationApiSupported) {
36-
return ConnectivityResult.none;
36+
return null;
3737
}
3838
return networkInformationToConnectivityResult(_networkInformation);
3939
}
4040

4141
Stream<ConnectivityResult> get _noopStream async* {
42-
yield ConnectivityResult.none;
42+
yield null;
4343
}
4444

4545
StreamController<ConnectivityResult> _connectivityResult;

packages/connectivity/connectivity_web/test/lib/main.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ void main() {
5252
});
5353

5454
group('unsupported browsers', () {
55-
test('null connection -> none', () {
55+
test('null connection -> null', () {
5656
ConnectivityPlugin plugin = ConnectivityPlugin.withConnection(null);
57-
expect(plugin.checkConnectivity(),
58-
completion(equals(ConnectivityResult.none)));
57+
expect(plugin.checkConnectivity(), completion(null));
5958
});
6059
});
6160
});
@@ -83,10 +82,9 @@ void main() {
8382
});
8483

8584
group('unsupported browsers', () {
86-
test('null connection -> none', () {
85+
test('null connection -> null', () {
8786
ConnectivityPlugin plugin = ConnectivityPlugin.withConnection(null);
88-
expect(plugin.onConnectivityChanged.last,
89-
completion(equals(ConnectivityResult.none)));
87+
expect(plugin.onConnectivityChanged.last, completion(null));
9088
});
9189
});
9290
});

0 commit comments

Comments
 (0)