build method

  1. @override
Future<Response> build()
override

Implementation

@override
Future<Response> build () async {
  final Map<String, String> fields = {};
  StreamedResponse response;

  if (httpFiles.isNotEmpty) {
    for (final field in httpPayload.entries) {
      fields.putIfAbsent(field.key, () => jsonEncode(field.value));
    }

    final request = MultipartRequest(httpMethod.uid, Uri.parse('$httpBaseUrl$httpUrl'))
      ..files.addAll(httpFiles)
      ..fields.addAll(fields)
      ..headers.addAll(httpHeaders);

    response = await request.send();
  } else {
    final request = Request(httpMethod.uid, Uri.parse('$httpBaseUrl$httpUrl'))
      ..body = jsonEncode(httpPayload)
      ..headers.addAll(httpHeaders);

    response = await request.send();
  }

  return Response.bytes(await response.stream.toBytes(), response.statusCode);
}