hasInternetConnection method

Future<bool> hasInternetConnection()

Kiểm tra thực sự có Internet không (ping DNS)

Implementation

Future<bool> hasInternetConnection() async {
try {
  final request = await HttpClient()
      .headUrl(Uri.parse('https://www.google.com'))
      .timeout(const Duration(seconds: 5));

  final response = await request.close();
  if (kDebugMode) {
    print('[Internet] Status: ${response.statusCode}');
  }
  return response.statusCode == 200;
} catch (e) {
  if (kDebugMode) {
    print('[Internet] ❌ $e');
  }
  return false;
}
}