mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-30 14:36:47 +00:00
Hide dialogs when requesting info from server
- Significant speed increase - Also looks heaps o' better
This commit is contained in:
parent
bda0a76f26
commit
1ee54a00de
@ -105,15 +105,19 @@ class InvenTreeModel {
|
|||||||
/*
|
/*
|
||||||
* Reload this object, by requesting data from the server
|
* Reload this object, by requesting data from the server
|
||||||
*/
|
*/
|
||||||
Future<bool> reload(BuildContext context) async {
|
Future<bool> 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())
|
var response = await api.get(url, params: defaultGetFilters())
|
||||||
.timeout(Duration(seconds: 10))
|
.timeout(Duration(seconds: 10))
|
||||||
.catchError((e) {
|
.catchError((e) {
|
||||||
|
|
||||||
hideProgressDialog(context);
|
if (dialog) {
|
||||||
|
hideProgressDialog(context);
|
||||||
|
}
|
||||||
|
|
||||||
if (e is TimeoutException) {
|
if (e is TimeoutException) {
|
||||||
showErrorDialog(context, "Timeout", "No response from server");
|
showErrorDialog(context, "Timeout", "No response from server");
|
||||||
@ -127,8 +131,10 @@ class InvenTreeModel {
|
|||||||
if (response == null) {
|
if (response == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hideProgressDialog(context);
|
if (dialog) {
|
||||||
|
hideProgressDialog(context);
|
||||||
|
}
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
print("Error retrieving data");
|
print("Error retrieving data");
|
||||||
@ -182,7 +188,7 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the detail view for the associated pk
|
// Return the detail view for the associated pk
|
||||||
Future<InvenTreeModel> get(BuildContext context, int pk, {Map<String, String> filters}) async {
|
Future<InvenTreeModel> get(BuildContext context, int pk, {Map<String, String> filters, bool dialog = false}) async {
|
||||||
|
|
||||||
// TODO - Add "timeout"
|
// TODO - Add "timeout"
|
||||||
// TODO - Add error catching
|
// TODO - Add error catching
|
||||||
@ -204,13 +210,17 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
print("GET: $addr ${params.toString()}");
|
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)
|
var response = await api.get(addr, params: params)
|
||||||
.timeout(Duration(seconds: 10))
|
.timeout(Duration(seconds: 10))
|
||||||
.catchError((e) {
|
.catchError((e) {
|
||||||
|
|
||||||
hideProgressDialog(context);
|
if (dialog) {
|
||||||
|
hideProgressDialog(context);
|
||||||
|
}
|
||||||
|
|
||||||
if (e is TimeoutException) {
|
if (e is TimeoutException) {
|
||||||
showErrorDialog(context, "Timeout", "No response from server");
|
showErrorDialog(context, "Timeout", "No response from server");
|
||||||
@ -272,7 +282,7 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return list of objects from the database, with optional filters
|
// Return list of objects from the database, with optional filters
|
||||||
Future<List<InvenTreeModel>> list(BuildContext context, {Map<String, String> filters, bool dialog=true}) async {
|
Future<List<InvenTreeModel>> list(BuildContext context, {Map<String, String> filters, bool dialog=false}) async {
|
||||||
|
|
||||||
if (filters == null) {
|
if (filters == null) {
|
||||||
filters = {};
|
filters = {};
|
||||||
@ -304,9 +314,7 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e is TimeoutException) {
|
if (e is TimeoutException) {
|
||||||
if (dialog) {
|
showErrorDialog(context, "Timeout", "No response from server");
|
||||||
showErrorDialog(context, "Timeout", "No response from server");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Re-throw the error
|
// Re-throw the error
|
||||||
throw e;
|
throw e;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user