post method
POST:
Sends a POST request to the specified endpoint with the provided body.
Returns the response data on success, or handles errors using _handleError.
endpoint: The API endpoint to send the POST request to.
body: The data to include in the POST request body.
Implementation
Future<dynamic> post(
String endpoint,
dynamic body, {
Map<String, dynamic> query = const {},
CancelToken? cancelToken,
Options? options,
Function(int, int)? onSendProgress,
Function(int, int)? onReceiveProgress,
}) async {
try {
final response = await _dio.post(
endpoint,
data: jsonEncode(body),
queryParameters: query,
cancelToken: cancelToken,
options: options,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
if (isApiLoggerEnable) {
await _sqfLiteService.add(data: {
"url": response.realUri.toString(),
"request": jsonEncode(response.requestOptions.data),
"response": jsonEncode(response.data),
"statusCode": response.statusCode,
"error": "No Error",
"header": jsonEncode(response.headers.map),
"method": response.requestOptions.method,
"timestamp": DateTime.now().toIso8601String(),
});
}
return response.data;
} catch (e, s) {
return _handleError(e, s);
}
}