From 81602512a5b35fbfbd3ceaa67cf81da768d4d2e9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 15 Aug 2021 13:44:27 +1000 Subject: [PATCH] Display error message when form submission returns error --- assets/release_notes.md | 5 ++++- lib/api.dart | 4 ++-- lib/api_form.dart | 8 +++++++- lib/widget/submit_feedback.dart | 1 - 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/assets/release_notes.md b/assets/release_notes.md index 6460a48a..6e493724 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -4,9 +4,12 @@ ### 0.4.4 - August 2021 --- +- Add ability to create new Part Categories +- Add ability to create new Parts +- Add ability to create new Stock Locations - App bar now always displays "back" button - Display "batch code" information for stock item -- Display "packagin" information for stock item +- Display "packaging" information for stock item ### 0.4.3 - August 2021 --- diff --git a/lib/api.dart b/lib/api.dart index f47feccb..62d49168 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -540,7 +540,7 @@ class InvenTreeAPI { * Perform a HTTP POST request * Returns a json object (or null if unsuccessful) */ - Future post(String url, {Map body = const {}, int expectedStatusCode=201}) async { + Future post(String url, {Map body = const {}, int? expectedStatusCode=201}) async { HttpClientRequest? request = await apiRequest(url, "POST"); @@ -763,7 +763,7 @@ class InvenTreeAPI { * Perform a HTTP GET request * Returns a json object (or null if did not complete) */ - Future get(String url, {Map params = const {}, int expectedStatusCode=200}) async { + Future get(String url, {Map params = const {}, int? expectedStatusCode=200}) async { HttpClientRequest? request = await apiRequest( url, diff --git a/lib/api_form.dart b/lib/api_form.dart index 5cd97af5..ed4b821a 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -597,12 +597,14 @@ class _APIFormWidgetState extends State { if (method == "POST") { return await InvenTreeAPI().post( url, - body: data + body: data, + expectedStatusCode: null ); } else { return await InvenTreeAPI().patch( url, body: data, + expectedStatusCode: null ); } @@ -660,6 +662,10 @@ class _APIFormWidgetState extends State { return; case 400: // Form submission / validation error + showSnackIcon( + L10().error, + success: false + ); // Update field errors for (var field in fields) { diff --git a/lib/widget/submit_feedback.dart b/lib/widget/submit_feedback.dart index a4f60787..b335d6f0 100644 --- a/lib/widget/submit_feedback.dart +++ b/lib/widget/submit_feedback.dart @@ -1,6 +1,5 @@ -import 'package:email_validator/email_validator.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';