I have a network call to be executed. But before doing that I need to check whether the device have internet connectivity.
The connectivity plugin states in its docs that it only provides information if there is a network connection, but not if the network is connected to the Internet.
Use this code:
import 'dart:io';
...
try {
final result = await InternetAddress.lookup('example.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
print('connected');
}
} on SocketException catch (_) {
print('not connected');
}
Also Read:
How to give Internet access to android application