HttpRequestBody constructor

HttpRequestBody(
  1. Object? content,
  2. String? type, [
  3. Map<String, Object?>? parameters
])

Implementation

HttpRequestBody(Object? content, String? type,
    [Map<String, Object?>? parameters]) {
  _contentType = normalizeType(type);

  var parametersMapStr = _toParametersMapOfString(parameters);

  if (content is HttpBodyBuilder) {
    var f = content;
    content = f(parametersMapStr ?? {});
  } else if (content is HttpBodyBuilderTyped) {
    var f = content;
    content = f(parametersMapStr ?? {}, _contentType);
  } else if (content is Function) {
    var f = content;
    content = f();
  }

  if (content == null) {
    _content = null;
  } else if (content is HttpBody) {
    _content = content;
  } else if (!isJSONType && content is List<int>) {
    _content = HttpBody.from(content, MimeType.parse(_contentType));
  } else if (content is String) {
    _content = HttpBody.from(content, MimeType.parse(_contentType));
  } else if (isJSONType ||
      (_contentType == null && (content is Map || content is List))) {
    _contentType ??= MimeType.applicationJson;
    var jsonEncoded = encodeJSON(content);
    _content = HttpBody.from(jsonEncoded, MimeType.parse(_contentType));
  } else {
    _content =
        HttpBody.from(content.toString(), MimeType.parse(_contentType));
  }
}