From 1ee54a00de84895c3c96f26b3c39e7648012a3be Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 4 Feb 2021 23:36:55 +1100 Subject: [PATCH] Hide dialogs when requesting info from server - Significant speed increase - Also looks heaps o' better --- lib/inventree/model.dart | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index 2dcf6aaf..c9bbc801 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -105,15 +105,19 @@ class InvenTreeModel { /* * Reload this object, by requesting data from the server */ - Future reload(BuildContext context) async { + Future reload(BuildContext context, {bool dialog = false}) async { - showProgressDialog(context, "Refreshing data", "Refreshing data for ${NAME}"); + if (dialog) { + showProgressDialog(context, "Refreshing data", "Refreshing data for ${NAME}"); + } var response = await api.get(url, params: defaultGetFilters()) .timeout(Duration(seconds: 10)) .catchError((e) { - hideProgressDialog(context); + if (dialog) { + hideProgressDialog(context); + } if (e is TimeoutException) { showErrorDialog(context, "Timeout", "No response from server"); @@ -127,8 +131,10 @@ class InvenTreeModel { if (response == null) { return false; } - - hideProgressDialog(context); + + if (dialog) { + hideProgressDialog(context); + } if (response.statusCode != 200) { print("Error retrieving data"); @@ -182,7 +188,7 @@ class InvenTreeModel { } // Return the detail view for the associated pk - Future get(BuildContext context, int pk, {Map filters}) async { + Future get(BuildContext context, int pk, {Map filters, bool dialog = false}) async { // TODO - Add "timeout" // TODO - Add error catching @@ -204,13 +210,17 @@ class InvenTreeModel { print("GET: $addr ${params.toString()}"); - showProgressDialog(context, "Requesting Data", "Requesting ${NAME} data from server"); + if (dialog) { + showProgressDialog(context, "Requesting Data", "Requesting ${NAME} data from server"); + } var response = await api.get(addr, params: params) .timeout(Duration(seconds: 10)) .catchError((e) { - hideProgressDialog(context); + if (dialog) { + hideProgressDialog(context); + } if (e is TimeoutException) { showErrorDialog(context, "Timeout", "No response from server"); @@ -272,7 +282,7 @@ class InvenTreeModel { } // Return list of objects from the database, with optional filters - Future> list(BuildContext context, {Map filters, bool dialog=true}) async { + Future> list(BuildContext context, {Map filters, bool dialog=false}) async { if (filters == null) { filters = {}; @@ -304,9 +314,7 @@ class InvenTreeModel { } if (e is TimeoutException) { - if (dialog) { - showErrorDialog(context, "Timeout", "No response from server"); - } + showErrorDialog(context, "Timeout", "No response from server"); } else { // Re-throw the error throw e;