length property Null safety

int length

The total length of the request body, in bytes. This is calculated from fields and files and cannot be set manually.

Implementation

int get length {
  var length = 0;
  fields.forEach((entry) {
    length += '--'.length +
        _BOUNDARY_LENGTH +
        '\r\n'.length +
        utf8.encode(_headerForField(entry.key, entry.value)).length +
        utf8.encode(entry.value).length +
        '\r\n'.length;
  });

  for (var file in files) {
    length += '--'.length +
        _BOUNDARY_LENGTH +
        '\r\n'.length +
        utf8.encode(_headerForFile(file)).length +
        file.value.length +
        '\r\n'.length;
  }

  return length + '--'.length + _BOUNDARY_LENGTH + '--\r\n'.length;
}