Body<T> constructor

Body<T>(
  1. T data
)

Body create available body types

Json format : JsonBody, Uint8List : BinaryBody, Text : HtmlBody

To ensure text use TextBody

Implementation

factory Body(T data) {
  if (data is Body<T>) {
    return data;
  }
  if (data is List<int>) {
    return BinaryBody(data as Uint8List) as Body<T>;
  }
  if (data is Map<String, dynamic> || data is List) {
    return JsonBody(data) as Body<T>;
  } else if (data is String) {
    if (data.startsWith("<")) {
      return HtmlBody(data) as Body<T>;
    }
    return StringBody(data) as Body<T>;
  }

  return Body._(data);
}