Skip to content

Commit 6f6923d

Browse files
committed
docs(connectivity_plus): document in README, example app, and the hasConnectivity extension getter
1 parent f62a52f commit 6f6923d

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

packages/connectivity_plus/connectivity_plus/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ import 'package:connectivity_plus/connectivity_plus.dart';
4040
4141
final List<ConnectivityResult> connectivityResult = await (Connectivity().checkConnectivity());
4242
43+
// Determines whether any active network connection exists.
44+
if (connectivityResult.hasConnectivity) {
45+
// Connectivity available (regardless of the underlying transport).
46+
}
47+
4348
// This condition is for demo purposes only to explain every connection type.
4449
// Use conditions which work for your requirements.
4550
if (connectivityResult.contains(ConnectivityResult.mobile)) {

packages/connectivity_plus/connectivity_plus/example/lib/main.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ class _MyHomePageState extends State<MyHomePage> {
101101
mainAxisSize: MainAxisSize.min,
102102
children: [
103103
const Spacer(flex: 2),
104+
Text(_connectionStatus.hasConnectivity
105+
? 'Connectivity available'
106+
: 'No connectivity'),
107+
const Spacer(flex: 2),
104108
Text(
105109
'Active connection types:',
106110
style: Theme.of(context).textTheme.headlineMedium,

packages/connectivity_plus/connectivity_plus/lib/connectivity_plus.dart

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,10 @@ class Connectivity {
4141
/// status changes, this is a known issue that only affects simulators.
4242
/// For details see https://github.com/fluttercommunity/plus_plugins/issues/479.
4343
///
44-
/// The emitted list is never empty.
45-
/// {@template no_connectivity_case}
46-
/// In case of no connectivity, the list contains
44+
/// The emitted list is never empty. In case of no connectivity, the list contains
4745
/// a single element of [ConnectivityResult.none]. Note also that this is the only
4846
/// case where [ConnectivityResult.none] is present.
4947
///
50-
/// Use `hasConnectivity` to determine whether any active network connection exists:
51-
///
52-
/// ```dart
53-
/// final result = await checkConnectivity();
54-
/// print(result.hasConnectivity);
55-
/// ```
56-
/// {@endtemplate}
57-
///
5848
/// This method applies [Stream.distinct] over the received events to ensure
5949
/// only emitting when connectivity changes.
6050
Stream<List<ConnectivityResult>> get onConnectivityChanged {
@@ -67,8 +57,9 @@ class Connectivity {
6757
/// make a network request, it only gives you the radio status. Instead, listen
6858
/// for connectivity changes via [onConnectivityChanged] stream.
6959
///
70-
/// The returned list is never empty.
71-
/// {@macro no_connectivity_case}
60+
/// The returned list is never empty. In case of no connectivity, the list contains
61+
/// a single element of [ConnectivityResult.none]. Note also that this is the only
62+
/// case where [ConnectivityResult.none] is present.
7263
Future<List<ConnectivityResult>> checkConnectivity() {
7364
return _platform.checkConnectivity();
7465
}

packages/connectivity_plus/connectivity_plus_platform_interface/lib/src/enums.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum ConnectivityResult {
3838
}
3939

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

0 commit comments

Comments
 (0)