Skip to content

Commit 9fcf342

Browse files
ditmanEdwinRomelta
authored andcommitted
[connectivity_platform_interface] Add ConnectivityResult.unknown. (flutter#2560)
Some platforms might not be able to determine the connectivity status of the device on which the app is running (like some desktop Web browsers). This allows users of the `connectivity` plugin to distinguish between "no connectivity" and "connectivity couldn't be determined". This requires a Major Version bump for users of the plugin who may be switch/case on ConnectivityResult values, since Dart forces users to be exhaustive in those cases (if they don't have a "default" entry, this new value becomes a compilation error in their code). This will also cause a Major Version bump in the core `connectivity` plugin itself. Note that by default, the ConnectivityResults returned by the MethodChannel implementation will now default to 'unknown' if they're not explicitly "none", so this might have some effect in your code!
1 parent 4cb8e06 commit 9fcf342

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

packages/connectivity/connectivity_platform_interface/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.0
2+
3+
* Added `ConnectivityResult.unknown`, for the cases where the plugin is unable to determine the
4+
connectivity status of the device. _(This happens mostly in the `web` platform.)_
5+
16
## 1.0.3
27

38
* Make the pedantic dev_dependency explicit.

packages/connectivity/connectivity_platform_interface/lib/src/enums.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ enum ConnectivityResult {
77
mobile,
88

99
/// None: Device not connected to any network
10-
none
10+
none,
11+
12+
/// Unknown: The plugin wasn't able to determine the connectivity status of the device
13+
unknown,
1114
}
1215

1316
/// The status of the location service authorization.

packages/connectivity/connectivity_platform_interface/lib/src/utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ ConnectivityResult parseConnectivityResult(String state) {
88
case 'mobile':
99
return ConnectivityResult.mobile;
1010
case 'none':
11-
default:
1211
return ConnectivityResult.none;
12+
default:
13+
return ConnectivityResult.unknown;
1314
}
1415
}
1516

packages/connectivity/connectivity_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A common platform interface for the connectivity plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 1.0.3
6+
version: 2.0.0
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)