From 12f4a4fa388395e1468a81401ec656a04417de67 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 7 Feb 2021 09:43:07 +1100 Subject: [PATCH] Fixed "await" for refreshable states - Progress indicator stays in place until calls are completed --- lib/widget/category_display.dart | 4 ++-- lib/widget/company_list.dart | 2 +- lib/widget/location_display.dart | 32 +++++++++++++++---------------- lib/widget/part_stock_detail.dart | 1 - 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index a429f0d7..5e26daf9 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -62,7 +62,7 @@ class _CategoryDisplayState extends RefreshableState { int pk = category?.pk ?? -1; // Request a list of sub-categories under this one - InvenTreePartCategory().list(context, filters: {"parent": "$pk"}).then((var cats) { + await InvenTreePartCategory().list(context, filters: {"parent": "$pk"}).then((var cats) { _subcategories.clear(); for (var cat in cats) { @@ -76,7 +76,7 @@ class _CategoryDisplayState extends RefreshableState { }); // Request a list of parts under this category - InvenTreePart().list(context, filters: {"category": "$pk"}).then((var parts) { + await InvenTreePart().list(context, filters: {"category": "$pk"}).then((var parts) { _parts.clear(); for (var part in parts) { diff --git a/lib/widget/company_list.dart b/lib/widget/company_list.dart index 8a44faa1..deada540 100644 --- a/lib/widget/company_list.dart +++ b/lib/widget/company_list.dart @@ -60,7 +60,7 @@ class _CompanyListState extends RefreshableState { @override Future request(BuildContext context) async { - InvenTreeCompany().list(context, filters: _filters).then((var companies) { + await InvenTreeCompany().list(context, filters: _filters).then((var companies) { _companies.clear(); diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 49223c14..6e8563de 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -68,7 +68,7 @@ class _LocationDisplayState extends RefreshableState { int pk = location?.pk ?? -1; // Request a list of sub-locations under this one - InvenTreeStockLocation().list(context, filters: {"parent": "$pk"}).then((var locs) { + await InvenTreeStockLocation().list(context, filters: {"parent": "$pk"}).then((var locs) { _sublocations.clear(); for (var loc in locs) { @@ -76,23 +76,21 @@ class _LocationDisplayState extends RefreshableState { _sublocations.add(loc); } } - - setState(() {}); - - // Request a list of stock-items under this one - InvenTreeStockItem().list(context, filters: {"location": "$pk"}).then((var items) { - _items.clear(); - - for (var item in items) { - if (item is InvenTreeStockItem) { - _items.add(item); - } - } - - setState(() {}); - }); - }); + + setState(() {}); + + await InvenTreeStockItem().list(context, filters: {"location": "$pk"}).then((var items) { + _items.clear(); + + for (var item in items) { + if (item is InvenTreeStockItem) { + _items.add(item); + } + } + }); + + setState(() {}); } Widget locationDescriptionCard() { diff --git a/lib/widget/part_stock_detail.dart b/lib/widget/part_stock_detail.dart index 0bd6a5f9..36528351 100644 --- a/lib/widget/part_stock_detail.dart +++ b/lib/widget/part_stock_detail.dart @@ -46,7 +46,6 @@ class _PartStockDisplayState extends RefreshableState { await part.reload(context); await part.getStockItems(context); - print("request"); setState(() { }); }