isOnline method
Checks if the device has an active internet connection.
Returns true if online, false if offline or if an error occurs.
Implementation
Future<bool> isOnline() async {
try {
final response = await http.get(Uri.parse('https://www.google.com'));
return response.statusCode == 200;
} on SocketException {
debugPrint('No internet connection.');
return false;
} catch (e) {
debugPrint('Unknown error while checking connectivity: $e');
return false;
}
}