body property

  1. @override
dynamic body
inherited

Gets this request's body as a JSON Map or List.

By default, the body of this FormRequest will is an empty Map.

The returned Map is modifiable, allowing incremental field assignment like so:

FormRequest request = new FormRequest()
  ..body['foo'] = 'bar'
  ..body['bar'] = 'baz';

Prior to sending, this request body will be translated to the equivalent query string. Depending on the platform, this may then be encoded to bytes. Be sure to set encoding if this request body should be encoded with something other than the default utf-8.

Implementation

@override
dynamic get body => _source;
  1. @override
void body=(dynamic jsonBody)
inherited

Sets this request's form body. The given Map should represent the form fields where each key-value pair is a field's name and value.

Prior to sending, this request body will be translated to the equivalent query string. Depending on the platform, this may then be encoded to bytes. Be sure to set encoding if this request body should be encoded with something other than the default utf-8.

Implementation

@override
set body(dynamic jsonBody) {
  verifyUnsent();
  // Store the source so it can be returned from the getter without having to
  // decode it again.
  _source = jsonBody;

  // Encode immediately so that we can attempt decoding it such that invalid
  // JSON will result in an exception now rather than later.
  _encodedJson = json.encode(jsonBody);
  json.decode(_encodedJson!);
}