Skip to content

feat(connectivity_plus): add checkConnectivity.hasConnectivity() utility getter#3842

Open
EchoEllet wants to merge 4 commits into
fluttercommunity:mainfrom
EchoEllet:feat/hasConnectivity-utility
Open

feat(connectivity_plus): add checkConnectivity.hasConnectivity() utility getter#3842
EchoEllet wants to merge 4 commits into
fluttercommunity:mainfrom
EchoEllet:feat/hasConnectivity-utility

Conversation

@EchoEllet

@EchoEllet EchoEllet commented May 27, 2026

Copy link
Copy Markdown
Contributor

Description

A very minor feature that is commonly used (e.g., serverpod_flutter):

final result = await checkConnectivity();
print(result.hasConnectivity);

Related Issues

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@EchoEllet

Copy link
Copy Markdown
Contributor Author

This PR does not modify sensors_plus, so this CI failure is most likely irrelevant.

@EchoEllet EchoEllet force-pushed the feat/hasConnectivity-utility branch from 69026c5 to e13be4c Compare May 27, 2026 23:05
@vbuberen vbuberen force-pushed the feat/hasConnectivity-utility branch from e13be4c to 958478a Compare July 7, 2026 18:40

@vbuberen vbuberen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but there is some work to do before we can merge this.

My main suggestion is to export extension via show as I suggested in one of my review comments.

Additionally, let's add mention and code example with the new extension to the README file and the example app, so it is easy to find for package users.

///
/// ```dart
/// final result = await checkConnectivity();
/// print(result.hasConnectivity);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't work the way it is described as currently calls like checkConnectivity() are not done without Connectivity() class. And hasConnectivity is only available if there is an import of 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart' in the file.
So this doc comment is misleading and needs an improvement. I would suggest to move this example comment about hasConnectivity to be above the extension itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to move this example comment about hasConnectivity to be above the extension itself.

ConnectivityResultListX is inside connectivity_plus_platform_interface, so it should probably not assume the API shape of code that depends on connectivity_plus.

I would avoid the reference to Connectivity() entirely inside the platform interface package.

So this doc comment is misleading and needs an improvement.

With the proposed change, consumers cannot find this extension by only reading connectivity_plus.

I think we can add a doc comment to hasConnectivity instead:

extension ConnectivityResultListX on List<ConnectivityResult> {
  /// Returns whether any active network connection exists.
  bool get hasConnectivity =>
      !(length == 1 && first == ConnectivityResult.none);
}

And then document it in README.md of connectivity_plus instead?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the new extension here to avoid the need for additional import of platform interface by package users.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause a temporary Dart analysis warning since connectivity_plus depends on connectivity_plus_platform_interface from pub.dev, and ConnectivityResultListX does not exist in the latest published version.

Should I add a temporary dependency override, or leave that to the project maintainers?

We also probably want to validate whether ConnectivityResultListX is a good name, because changing it later is a breaking change.

Comment thread packages/connectivity_plus/connectivity_plus/lib/connectivity_plus.dart Outdated
@EchoEllet EchoEllet force-pushed the feat/hasConnectivity-utility branch 2 times, most recently from 3bd89c3 to 966f514 Compare July 7, 2026 22:58
@EchoEllet EchoEllet force-pushed the feat/hasConnectivity-utility branch from 966f514 to 6f6923d Compare July 7, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: Add hasConnectivity getter extension to List<ConnectivityResult>

2 participants