checkConnection method

Future<bool> checkConnection()

Проверяет наличие интернет-соединения.

Возвращает Future<bool>:

  • true, если устройство подключено к сети,
  • false, если отсутствует подключение.

Implementation

Future<bool> checkConnection() async {
  try {
    final connectivityResult = await Connectivity().checkConnectivity();
    if (connectivityResult.contains(ConnectivityResult.none)) return false;
    return true;
  } catch (_) {
    return false;
  }
}