From 7c76492edd30eb9195a1c3e9846dd87cf261cb1b Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 26 Feb 2020 16:15:44 -0800 Subject: [PATCH 1/2] [connectivity_platform_interface] Add `ConnectivityResult.unknown`. 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. --- .../connectivity_platform_interface/CHANGELOG.md | 5 +++++ .../connectivity_platform_interface/lib/src/enums.dart | 5 ++++- .../connectivity_platform_interface/pubspec.yaml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/connectivity/connectivity_platform_interface/CHANGELOG.md b/packages/connectivity/connectivity_platform_interface/CHANGELOG.md index d249985c65f4..3766106f9b0b 100644 --- a/packages/connectivity/connectivity_platform_interface/CHANGELOG.md +++ b/packages/connectivity/connectivity_platform_interface/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.0 + +* Added `ConnectivityResult.unknown`, for the cases where the plugin is unable to determine the +connectivity status of the device. _(This happens mostly in the `web` platform.)_ + ## 1.0.3 * Make the pedantic dev_dependency explicit. diff --git a/packages/connectivity/connectivity_platform_interface/lib/src/enums.dart b/packages/connectivity/connectivity_platform_interface/lib/src/enums.dart index 9d8cef9e1a66..a2d5f8d10f10 100644 --- a/packages/connectivity/connectivity_platform_interface/lib/src/enums.dart +++ b/packages/connectivity/connectivity_platform_interface/lib/src/enums.dart @@ -7,7 +7,10 @@ enum ConnectivityResult { mobile, /// None: Device not connected to any network - none + none, + + /// Unknown: The plugin wasn't able to determine the connectivity status of the device + unknown, } /// The status of the location service authorization. diff --git a/packages/connectivity/connectivity_platform_interface/pubspec.yaml b/packages/connectivity/connectivity_platform_interface/pubspec.yaml index 78f9473c4452..489515cebc51 100644 --- a/packages/connectivity/connectivity_platform_interface/pubspec.yaml +++ b/packages/connectivity/connectivity_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the connectivity plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 1.0.3 +version: 2.0.0 dependencies: flutter: From 3d192a55ba21a041d910a5c565a9a3cfef8ca4bb Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 26 Feb 2020 16:41:09 -0800 Subject: [PATCH 2/2] Return unknown connectivity by default. --- .../connectivity_platform_interface/lib/src/utils.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/connectivity/connectivity_platform_interface/lib/src/utils.dart b/packages/connectivity/connectivity_platform_interface/lib/src/utils.dart index 2ae22e1c9fc3..ae412e89c7c9 100644 --- a/packages/connectivity/connectivity_platform_interface/lib/src/utils.dart +++ b/packages/connectivity/connectivity_platform_interface/lib/src/utils.dart @@ -8,8 +8,9 @@ ConnectivityResult parseConnectivityResult(String state) { case 'mobile': return ConnectivityResult.mobile; case 'none': - default: return ConnectivityResult.none; + default: + return ConnectivityResult.unknown; } }