setBody method

void setBody(
  1. Object body
)

Sets the body to body, a String (encoded in UTF-8) or a list of bytes, and sets Content-Length to match. Throws an ArgumentError for anything else. It does not set Content-Type.

Implementation

void setBody(Object body) {
  _body = switch (body) {
    final String text => utf8.encode(text),
    final Uint8List bytes => bytes,
    final List<int> bytes => Uint8List.fromList(bytes),
    _ => throw ArgumentError.value(body, 'body', 'a String or bytes'),
  };
  headers.contentLength = _body.length;
}