asBytes method

Uint8List asBytes()

Returns this request/response body as a list of bytes.

Implementation

Uint8List asBytes() {
  if (_bytes == null) {
    List<int> encoded;
    try {
      encoded = encoding.encode(_body!);
    } on ArgumentError {
      throw ResponseFormatException(contentType, encoding, body: _body);
    }
    _bytes = Uint8List.fromList(encoded);
  }
  return _bytes!;
}