linkPostRequest<T extends Link> method
Future<RequestResult<T> >
linkPostRequest<T extends Link>(
- T link, {
- GlobalKey<
ScaffoldState> ? globalKey, - dynamic errorCallback()?,
- int timeout = 7,
Implementation
Future<RequestResult<T>> linkPostRequest<T extends Link>(T link,
{GlobalKey<ScaffoldState>? globalKey,
Function()? errorCallback,
int timeout = 7}) async {
http.Response response;
try {
response = await http
.post(Uri.parse(serverUrl), body: jsonEncode(link.getSendJSON()))
.timeout(Duration(seconds: timeout));
} on Exception catch (e) {
Debug.debugging("HttpPost", "http request timeout $e");
_showNetErrSnackBar(globalKey);
if (errorCallback != null) errorCallback();
return RequestResult(false, link);
}
if (response.statusCode == 200) {
try {
var json = jsonDecode(response.body);
link.receiveJSON(json);
return RequestResult(true, link,
result: json[BKConstants.BK_WORKING_RESULT]);
} catch (e, stack) {
String errorMessage =
"HttpRequest receive error, error message:$e, response body:${response.body}"
" link$link";
Debug.debugging("HttpRequest", errorMessage);
Debug.debugging("HttpRequest", stack.toString());
_showNetErrSnackBar(globalKey);
}
} else {
_showNetErrSnackBar(globalKey);
Debug.debugging("HttpRequest", "network error");
}
return RequestResult(false, link);
}