@@ -12,27 +12,37 @@ To start using Connectivity Plus, initialize the singleton, which will give you
12
12
final Connectivity _connectivity = Connectivity();
13
13
```
14
14
15
- ### WiFi or Cellular?
15
+ ### Connection type
16
16
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 .
18
18
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());
21
23
22
24
if (connectivityResult == ConnectivityResult.mobile) {
23
25
// I am connected to a mobile network.
24
26
} else if (connectivityResult == ConnectivityResult.wifi) {
25
27
// 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.
26
41
}
27
42
```
28
43
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
-
34
44
:::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 .
36
46
For instance, the app might have WiFi access but it might be a VPN or
37
47
a hotel WiFi with no access to internet.
38
48
:::
@@ -63,7 +73,6 @@ in the background starting with **Android 8.0**.
63
73
The broadcast is only useful when your application is in the ** foreground** .
64
74
:::
65
75
66
-
67
76
``` dart
68
77
// Initialize a variable with [none] status to avoid nulls at startup
69
78
ConnectivityResult connectivityResult = ConnectivityResult.none;
0 commit comments