postJson<T extends ResponseBase> method

  1. @protected
Future<T> postJson<T extends ResponseBase>({
  1. required RequestBase request,
  2. required T mapper(
    1. Map<String, dynamic>,
    2. Response response
    ),
  3. T orElse(
    1. dynamic,
    2. Response response
    )?,
  4. Options? options,
  5. bool cancelOnDispose = true,
  6. Map<String, dynamic> queryParameters = const {},
  7. int expectedStatusCode = 200,
  8. bool allowCache = true,
})

Perform a query using the "POST" method and using the JSON content type The body of the request is extracted from request Optionally pass queryParameters for query parameters attached to the request Use mapper to map the json response Optionally you can use the orElse to map other kind of response Optionally you can specify options to pass to Dio cancelOnDispose lets you cancel the request if this service is disposed expectedStatusCode to check the result of the request set allowCache to true to skip che expectedStatusCode when response

Implementation

@protected
Future<T> postJson<T extends ResponseBase>({
  required RequestBase request,
  required T Function(Map<String, dynamic>, Response response) mapper,
  T Function(dynamic, Response response)? orElse,
  Options? options,
  bool cancelOnDispose = true,
  Map<String, dynamic> queryParameters = const {},
  int expectedStatusCode = 200,
  bool allowCache = true,
}) async {
  final performer = () => dioInstance.post(
        request.endpoint,
        data: request.toJson(),
        queryParameters: queryParameters,
        options: options?.copyWith(
              contentType: 'application/json',
            ) ??
            Options(
              contentType: 'application/json',
            ),
        cancelToken: cancelOnDispose ? getNextToken() : null,
      );
  return _perform(performer, mapper, orElse, expectedStatusCode, allowCache);
}