import 'dart:async'; import 'dart:io'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:dio/dio.dart'; class NetworkConnectivity { // Future isInternetAvailable() async { // var connectivityResult = await (Connectivity().checkConnectivity()); // return connectivityResult != ConnectivityResult.none; // } Future isInternetAvailable() async { var connectivityResult = await Connectivity().checkConnectivity(); if (connectivityResult == ConnectivityResult.none) { return false; } else { try { // final result = await InternetAddress.lookup('google.com'); final result = await Dio().get('www.google.com'); if (result.statusCode == 200) { // if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) { return true; //} } return false; } on SocketException catch (_) { return false; } } } }