put function
Implementation
Future<Response> put({
final Function(Response)? onResponse,
final Function()? onTimeout,
final Function()? onNoInternet,
required final String tag,
required final String url,
final Map<String, String> headers = defaultJsonHeaders,
final dynamic body,
final Map<String, String>? params,
final Duration timeoutDuration = defaultTimeoutDuration,
}) async {
final fullUrl = await getFullURL(url, params);
http.Response response = http.Response('', 444);
try {
response = await http
.put(Uri.parse(fullUrl), headers: headers, body: body)
.timeout(
timeoutDuration,
onTimeout: () {
printDebugLogFail(
tag: tag,
message: '\nRequest URL: $fullUrl'
'\nRequest Method: PUT'
'\nRequest Headers: ${getPrettyJSONString(headers)}'
'\nRequest Body: ${getPrettyJSONString(body)}'
'\nRequest Timeout: $timeoutDuration',
);
if (onTimeout != null) onTimeout();
return response;
},
).then((http.Response response) {
printDebugLogSuccess(
tag: tag,
message: '\nRequest URL: $fullUrl'
'\nRequest Method: PUT'
'\nRequest Headers: ${getPrettyJSONString(headers)}'
'\nRequest Body: ${getPrettyJSONString(body)}'
'\nResponse Code: ${response.statusCode}'
'\nResponse Body: ${getPrettyJSONString(response.body)}',
);
return response;
});
if (response.statusCode == 444) {
return Response(
status: ResponseStatus.timeout,
);
} else {
onResponse?.call(Response(
status: ResponseStatus.ok,
response: response,
));
return Response(
status: ResponseStatus.ok,
response: response,
);
}
} catch (_) {
if (await checkInternetConnection()) {
return Response(status: ResponseStatus.unknownException);
}
return Response(status: ResponseStatus.connectionError);
}
}