httpPut<T> method
Implementation
Future<ApiResponse<T>> httpPut<T>(
{body, required Function converter, bool isAuth = true, Map<String, dynamic>? queryParams, bool isContentTypeHeader = false}) async {
var url = createUri("${HttpX.instance.baseUrl}$this",queryParams);
try {
http.Response response =
await http.put(url, body: jsonEncode(body), headers: {
if (isAuth) HttpX.instance.headerName: await HttpX.instance.token(),
if(isContentTypeHeader)'Content-Type': 'application/json;charset=UTF-8',
if(isContentTypeHeader) 'Charset': 'utf-8'
});
print("response: " + response.body);
final prefix = '';
var resBody = response.body;
if (resBody.startsWith(prefix)) {
resBody = resBody.substring(prefix.length);
}
return ApiResponse<T>(
code: response.statusCode,
data: converter(jsonDecode(resBody)),
error: null);
} catch (error) {
print("error" + error.toString());
return ApiResponse<T>(
code: HttpStatus.internalServerError,
data: null,
error: error.toString());
}
}