2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

Handle form posting with complex "layered" data

- Handle data rendering
- Handle returned errors
This commit is contained in:
Oliver
2021-10-03 00:40:26 +10:00
parent 80b203ce7b
commit b7f9f1c55f
3 changed files with 88 additions and 17 deletions

View File

@ -485,11 +485,9 @@ class InvenTreeAPI {
// Perform a PATCH request
Future<APIResponse> patch(String url, {Map<String, String> body = const {}, int? expectedStatusCode}) async {
Map<String, String> _body = {};
Future<APIResponse> patch(String url, {Map<String, dynamic> body = const {}, int? expectedStatusCode}) async {
// Copy across provided data
body.forEach((K, V) => _body[K] = V);
Map<String, dynamic> _body = body;
HttpClientRequest? request = await apiRequest(url, "PATCH");
@ -599,7 +597,7 @@ class InvenTreeAPI {
* Upload a file to the given URL
*/
Future<APIResponse> uploadFile(String url, File f,
{String name = "attachment", String method="POST", Map<String, String>? fields}) async {
{String name = "attachment", String method="POST", Map<String, dynamic>? fields}) async {
var _url = makeApiUrl(url);
var request = http.MultipartRequest(method, Uri.parse(_url));
@ -607,8 +605,13 @@ class InvenTreeAPI {
request.headers.addAll(defaultHeaders());
if (fields != null) {
fields.forEach((String key, String value) {
request.fields[key] = value;
fields.forEach((String key, dynamic value) {
if (value == null) {
request.fields[key] = "";
} else {
request.fields[key] = value.toString();
}
});
}