postMethod static method
Implementation
static Future<Response> postMethod(
{required Uri url,
Map<String, String>? headers,
Map<String, dynamic>? body,
Map<String, String>? multipartFile}) async {
// print(url.path);
// AppUtils.log(Urls.appApiBaseUrl+url.path);
AppUtils.log(Urls.api+url.path);
AppUtils.log(headers);
AppUtils.log(body);
// AppUtils.log(multipartFile);
// AppUtils.log(body);
if (multipartFile != null) {
var request = MultipartRequest('POST', url);
if(headers != null){
request.headers.addAll(headers);
}
for (var entry in multipartFile.entries) {
String fieldName = entry.key;
String filePath = entry.value;
request.files.add(
await MultipartFile.fromPath(fieldName, filePath),
);
}
if (body != null) {
for (var entry in body.entries) {
request.fields[entry.key] = entry.value.toString();
}
}
var streamedResponse = await request.send();
var response = await Response.fromStream(streamedResponse);
return response;
} else {
return post(url, headers: headers, body: jsonEncode(body));
}
}