Skip to content

Commit 5510a4e

Browse files
authored
docs(connectivity_plus): Update usage documentation on website (#2019)
1 parent b6db3d0 commit 5510a4e

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

docs/connectivity_plus/usage.mdx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,37 @@ To start using Connectivity Plus, initialize the singleton, which will give you
1212
final Connectivity _connectivity = Connectivity();
1313
```
1414

15-
### WiFi or Cellular?
15+
### Connection type
1616

17-
Using Connectivity API, you can know whether the device is connected to WiFi or to cellular network.
17+
Using Connectivity API, you can find out which type of connection the device is using at the moment.
1818

19-
``` dart
20-
ConnectivityResult connectivityResult = await _connectivity.checkConnectivity();
19+
```dart
20+
import 'package:connectivity_plus/connectivity_plus.dart';
21+
22+
final connectivityResult = await (Connectivity().checkConnectivity());
2123
2224
if (connectivityResult == ConnectivityResult.mobile) {
2325
// I am connected to a mobile network.
2426
} else if (connectivityResult == ConnectivityResult.wifi) {
2527
// I am connected to a wifi network.
28+
} else if (connectivityResult == ConnectivityResult.ethernet) {
29+
// I am connected to a ethernet network.
30+
} else if (connectivityResult == ConnectivityResult.vpn) {
31+
// I am connected to a vpn network.
32+
// Note for iOS and macOS:
33+
// There is no separate network interface type for [vpn].
34+
// It returns [other] on any device (also simulator)
35+
} else if (connectivityResult == ConnectivityResult.bluetooth) {
36+
// I am connected to a bluetooth.
37+
} else if (connectivityResult == ConnectivityResult.other) {
38+
// I am connected to a network which is not in the above mentioned networks.
39+
} else if (connectivityResult == ConnectivityResult.none) {
40+
// I am not connected to any network.
2641
}
2742
```
2843

29-
Using `checkConnectivity()` method, you may get one of 3 network statuses:
30-
1. **Mobile:** connected to a mobile cellular network.
31-
2. **WiFi:** connected to WiFi access point.
32-
3. **None:** not connected at all.
33-
3444
:::caution
35-
Note that on **Android**, this does not guarantee connection to internet.
45+
Note that on **Android**, this does not guarantee connection to the Internet.
3646
For instance, the app might have WiFi access but it might be a VPN or
3747
a hotel WiFi with no access to internet.
3848
:::
@@ -63,7 +73,6 @@ in the background starting with **Android 8.0**.
6373
The broadcast is only useful when your application is in the **foreground**.
6474
:::
6575

66-
6776
``` dart
6877
// Initialize a variable with [none] status to avoid nulls at startup
6978
ConnectivityResult connectivityResult = ConnectivityResult.none;

0 commit comments

Comments
 (0)