transformRequest method Null safety

  1. @override
Future<String> transformRequest(
  1. RequestOptions options

transformRequest allows changes to the request data before it is sent to the server, but after the RequestInterceptor.

This is only applicable for request methods 'PUT', 'POST', and 'PATCH'


Future<String> transformRequest(RequestOptions options) async {
  var data = ?? '';
  if (data is! String) {
    if (_isJsonMime(options.contentType)) {
      return json.encode(;
    } else if (data is Map) {
      options.contentType = Headers.formUrlEncodedContentType;
      return Transformer.urlEncodeMap(data);
  return data.toString();