Skip to content

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

@EchoEllet

Description

@EchoEllet

Plugin

connectivity_plus

Use case

A convenient getter that makes the API design more self-explanatory and slightly easier to read:

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

In many cases, only the general connectivity state is required (connected vs disconnected), independent of the underlying transport (e.g., Wifi, Ethernet).

A very minor feature that is commonly used in published packages (e.g., serverpod_flutter).

Proposal

// connectivity_plus_platform_interface/lib/src/enums.dart

extension ConnectivityResultListX on List<ConnectivityResult> {
  bool get hasConnectivity =>
      !(length == 1 && first == ConnectivityResult.none);
}

This implementation respects the current doc comment of connectivity_plus:

/// The returned list is never empty. In case of no connectivity, the list contains
/// a single element of [ConnectivityResult.none]. Note also that this is the only
/// case where [ConnectivityResult.none] is present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions