I use the HTTP package to post a request to the server and handle errors but there is a net::ERR_TIMED_OUT error when sending a request to the server which I can not figure out how to handle it.
Here is my send request
Future<Session> login(String username, String password) async {
final request = Uri.https(
_baseUrlGeocoding,
'/login',
{'email': username.trim(), 'password': password},
);
try {
final response = await _httpClient.post(request);
if (response.statusCode != 200) {
throw LoginRequestServerFailure();
}
final responseJson = jsonDecode(response.body) as Map<String, dynamic>;
if (responseJson['message'] != 'OK') throw LoginCredentialsFailure();
return Session.fromJson(responseJson['data'] as Map<String, dynamic>);
} catch (error) {
print(error.toString());
throw InternetConnectionFailure();
}
}
After sending a request instead of catching an error debugger freezes at send request point and no error is thrown.In the console of the web I've got this error message:
POST https://sample.com/account?email=g81%40ekcsoft.com&password=123456 net::ERR_TIMED_OUT
How to handle net::ERR_TIMED_OUT error in flutter http package when send request to server?

write like this