connectivity_result.dart 1.23 KB
Newer Older
yenisleydi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import 'package:connectivity_plus/connectivity_plus.dart';

Future<void> checkConnecticity() async {
  final ConnectivityResult connectivityResult = await (Connectivity().checkConnectivity());

// This condition is for demo purposes only to explain every connection type.
// Use conditions which work for your requirements.
  if (connectivityResult==ConnectivityResult.mobile) {
// Mobile network available.
  } else if (connectivityResult==ConnectivityResult.wifi) {
// Wi-fi is available.
// Note for Android:
// When both mobile and Wi-Fi are turned on system will return Wi-Fi only as active network type
  } else if (connectivityResult==ConnectivityResult.ethernet) {
// Ethernet connection available.
  } else if (connectivityResult==ConnectivityResult.vpn) {
// Vpn connection active.
// Note for iOS and macOS:
// There is no separate network interface type for [vpn].
// It returns [other] on any device (also simulator)
  } else if (connectivityResult==ConnectivityResult.bluetooth) {
// Bluetooth connection available.
  } else if (connectivityResult==ConnectivityResult.other) {
// Connected to a network which is not in the above mentioned networks.
  } else if (connectivityResult==ConnectivityResult.none) {
// No available network types
  }
}