Skip to content

Commit 3bd89c3

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

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

packages/connectivity_plus/connectivity_plus/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ 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 (regardless of the underlying transport).
44+
print(connectivityResult.hasConnectivity);
45+
4346
// This condition is for demo purposes only to explain every connection type.
4447
// Use conditions which work for your requirements.
4548
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: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,10 @@ class Connectivity {
4242
/// For details see https://github.com/fluttercommunity/plus_plugins/issues/479.
4343
///
4444
/// The emitted list is never empty.
45-
/// {@template no_connectivity_case}
4645
/// In case of no connectivity, the list contains
4746
/// a single element of [ConnectivityResult.none]. Note also that this is the only
4847
/// case where [ConnectivityResult.none] is present.
4948
///
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-
///
5849
/// This method applies [Stream.distinct] over the received events to ensure
5950
/// only emitting when connectivity changes.
6051
Stream<List<ConnectivityResult>> get onConnectivityChanged {
@@ -68,7 +59,9 @@ class Connectivity {
6859
/// for connectivity changes via [onConnectivityChanged] stream.
6960
///
7061
/// The returned list is never empty.
71-
/// {@macro no_connectivity_case}
62+
/// In case of no connectivity, the list contains
63+
/// a single element of [ConnectivityResult.none]. Note also that this is the only
64+
/// case where [ConnectivityResult.none] is present.
7265
Future<List<ConnectivityResult>> checkConnectivity() {
7366
return _platform.checkConnectivity();
7467
}

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)