postData method
Implementation
Future postData(String url, dynamic json) async {
http.Response response;
try {
Dao.inst.httpHeaders == null
? response = await http
.post(Uri.parse(url), body: jsonEncode(json))
.timeout(Duration(seconds: Dao.inst.httpTimeout))
: response = await http
.post(Uri.parse(url),
headers: Dao.inst.httpHeaders, body: jsonEncode(json))
.timeout(Duration(seconds: Dao.inst.httpTimeout));
if (response.statusCode == 200) {
return response.body;
} else if (response.statusCode != 200 && Dao.inst.isDebug == true) {
throw ("Something went horribly wrong..." +
response.statusCode.toString() +
"...." +
response.body);
} else if (response.statusCode != 200 && Dao.inst.isDebug == false) {
return _liquidService.throwHTTPError(
response.statusCode.toString(), response.body);
}
} on TimeoutException catch (e) {
var connectivityResult = await _connectivity.checkConnectivity();
if (connectivityResult == ConnectivityResult.mobile ||
connectivityResult == ConnectivityResult.wifi) {
return _liquidService.throwConnectivityError();
} else {
return _liquidService.throwHTTPError('500', e.toString());
}
} catch (e) {
Dao.inst.isDebug == true
? throw (e)
: _liquidService.throwHTTPError('500', e.toString());
}
}