postForm method
Implementation
Future<void> postForm(String endpoint, Map<String, String> headers,
Map<String, String> body) async {
final Uri uri = Uri.parse('$url$endpoint');
try {
final http.MultipartRequest request = http.MultipartRequest('POST', uri)
..headers.addAll(headers)
..fields.addAll(body);
final http.StreamedResponse streamedResponse = await request.send();
final http.Response res =
await http.Response.fromStream(streamedResponse);
response = res.body;
httpCode = res.statusCode;
final Map<String, dynamic> jsonResponse = jsonDecode(response!);
errorMessage = jsonResponse['error']?['message'];
if (res.statusCode >= 400) {
error = res.reasonPhrase;
}
} catch (e) {
error = e.toString();
}
}