streamed method

Future streamed(
  1. dynamic method,
  2. dynamic url,
  3. dynamic headers, {
  4. dynamic payload,
  5. dynamic files,
  6. dynamic responseType,
})

Implementation

Future<dynamic> streamed(method, url, headers,
    {payload, files, responseType}) async {
  final request = http.MultipartRequest(method, url);
  request.headers.addAll(headers);
  if (payload != null) {
    request.fields.addAll(Map<String, String>.from(payload));
  }
  if (files != null) {
    for (dynamic file in files) {
      request.files.add(await http.MultipartFile.fromPath(
        file['array_key'],
        file['file'].path,
        contentType: MediaType("image", p.extension(file['file'].path)),
      ));
    }
  }
  http.StreamedResponse streamedResponse = await request.send();
  if (responseType == "stream") {
    return streamedResponse;
  }
  return await http.Response.fromStream(streamedResponse);
}