multiPart static method

Future<Response> multiPart(
  1. dynamic url, {
  2. String method = 'POST',
  3. Map<String, String>? fields,
  4. List<MultipartFile>? files,
  5. Map<String, String>? headers,
})

Implementation

static Future<Response> multiPart(url,
    {String method = 'POST',
    Map<String, String>? fields,
    List<http.MultipartFile>? files,
    Map<String, String>? headers}) async {
  try {
    final req = http.MultipartRequest(method, Uri.parse(url));

    if (fields != null) req.fields.addAll(fields);

    if (files != null) req.files.addAll(files);

    if (headers != null) req.headers.addAll(headers);

    http.Response response = await http.Response.fromStream(await req.send());

    return Response.fromJSON(json.decode(response.body));
  } catch (e, trace) {
    return Response(
        result: false,
        status: 500,
        message: requestFailedMessage,
        reporting: {
          'type': 'dart',
          'filename': 'repository.dart',
          'classname': 'Repository',
          'function': 'multiPart',
          'line': 173,
          'message': e.toString(),
          'trace': trace,
        });
  }
}