apiHealthCheck static method
Checks internet and api health
Implementation
static Future<bool> apiHealthCheck(String site, {int timeout = 5}) async {
try {
if (site.indexOf("?") > -1) {
site = site + "&";
} else {
site = site + "?";
}
site = site + "t=" + DateTime.now().millisecondsSinceEpoch.toString();
http.Response response = await http.get(Uri.parse(site)).timeout(
Duration(seconds: timeout),
onTimeout: () {
return http.Response('Error', 408);
},
);
return (response.statusCode >= 200 && response.statusCode < 300);
} catch (error) {
return false;
}
}