hasInternetConnection method
Kiểm tra internet có hoạt động thực sự không (ping Google)
Implementation
Future<bool> hasInternetConnection({
Duration timeout = const Duration(seconds: 3), // ⚡ Giảm timeout
}) async {
try {
final result = await InternetAddress.lookup(
'google.com',
).timeout(timeout);
return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
} on SocketException catch (_) {
return false;
} on TimeoutException catch (_) {
return false;
} catch (e) {
return false;
}
}