post method
Future<Response>
post(
{ - required String path,
- void onSendProgress(
- int,
- int
)?,
- void onReceiveProgress(
- int,
- int
)?,
- Map<String, dynamic>? queryParameters,
- String contentType = 'application/json',
- Map<String, dynamic>? body,
})
Implementation
Future<Response<dynamic>> post({
required String path,
void Function(int, int)? onSendProgress,
void Function(int, int)? onReceiveProgress,
Map<String, dynamic>? queryParameters,
String contentType = 'application/json',
Map<String, dynamic>? headers,
Map<String, dynamic>? body,
}) async {
final requestBody = jsonEncode(body);
//holds request options
final options = headers != null
? Options(
responseType: ResponseType.json,
contentType: contentType,
headers: headers)
: Options(
responseType: ResponseType.json,
contentType: contentType,
);
debugPrint(
'================DioClientExtended Post REQUEST================');
debugPrint('REQUEST BODY: $body');
try {
final response = await dioClient.post<dynamic>(
path,
queryParameters: queryParameters,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
options: options,
data: requestBody,
);
debugPrint(
'================DioClientExtended Post RESPONSE================');
debugPrint('STATUS CODE: ${response.statusCode}');
debugPrint('DATA: ${response.data}');
return response;
} on DioException catch (e) {
//any logging platform can be configured like firebase crashlytics
debugPrint('DioException: $e');
rethrow;
}
}