multipartPost method
Implementation
Future<HttpResponseMTPL> multipartPost(String url,
{required Map data,
Map<String, String>? headers,
String? picKey,
bool passRawData = false}) async {
if ((await checkConnection()) != ConnectivityResult.none) {
var request = http.MultipartRequest('POST', Uri.parse(endPoint + url));
headers = await getSessionData(headers ?? {}, passRawData: passRawData);
request.headers.addAll(headers);
final streamedResponse = await request.send();
data.forEach((key, value) {
if (key.toString().contains(picKey!)) {
request.files.add(value);
} else {
request.fields["$key"] = value;
}
});
final response = await http.Response.fromStream(streamedResponse);
print(utf8.decode(response.bodyBytes));
return HttpResponseMTPL(
statusCode: response.statusCode,
data: jsonDecode(utf8.decode(response.bodyBytes)),
);
} else {
if (noInternetScreen != null && context != null) {
await Navigator.push(
context!,
MaterialPageRoute(builder: (context) => noInternetScreen!),
);
return multipartPost(url,
data: data, headers: headers, passRawData: passRawData);
}
return Future.error(Strings.noInternet);
}
}