post method

Future<Response> post({
  1. required String path,
  2. void onSendProgress(
    1. int,
    2. int
    )?,
  3. void onReceiveProgress(
    1. int,
    2. int
    )?,
  4. Map<String, dynamic>? queryParameters,
  5. String contentType = 'application/json',
  6. Map<String, dynamic>? headers,
  7. 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;
  }
}