postJsonAPI method

Future<BaseResponse> postJsonAPI(
  1. String url,
  2. dynamic data,
  3. dynamic body, {
  4. bool hasHeader = true,
  5. int timeout = 20,
})

Implementation

Future<BaseResponse> postJsonAPI(String url, data, body, {bool hasHeader = true, int timeout = 20}) async {
  final baseResponse = BaseResponse();
  try {
    final headers = {
      'Content-Type': 'application/json; charset=utf-8'
    };
    headers.addAll(await _getHeader(hasAuthen: hasHeader));
    final response = await http.post(Uri.parse(baseUrl + url),
        headers: headers, body: jsonEncode(body)).timeout(Duration(seconds: timeout));
    baseResponse.fromJson(jsonDecode(response.body), data);
  } catch (e) {
    return _responseError(baseResponse, e);
  }
  return baseResponse;
}