From f652bebd83bb6f7dc72ec0496c0cda729c7343e0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 29 Jul 2022 19:30:22 +1000 Subject: [PATCH] Show loading overlay for "toggle star" operation (#192) * Show loading overlay for "toggle star" operation * Improve loading speed of PartDetail widget * Improve loading of StockDetail widget --- lib/widget/part_detail.dart | 50 ++++++++++++++++++++++++++++-------- lib/widget/stock_detail.dart | 9 +++++-- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index ae15e9c0..15cc7011 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -22,6 +22,9 @@ import "package:inventree/widget/stock_detail.dart"; import "package:inventree/widget/stock_list.dart"; +/* + * Widget for displaying a detail view of a single Part instance + */ class PartDetailWidget extends StatefulWidget { const PartDetailWidget(this.part, {Key? key}) : super(key: key); @@ -118,31 +121,56 @@ class _PartDisplayState extends RefreshableState { } } - await part.getTestTemplates(); + // Request part test templates + part.getTestTemplates().then((value) { + setState(() { + }); + }); - attachmentCount = await InvenTreePartAttachment().count( + // Request the number of attachments + InvenTreePartAttachment().count( filters: { - "part": part.pk.toString() + "part": part.pk.toString(), } - ); + ).then((int value) { + setState(() { + attachmentCount = value; + }); + }); - bomCount = await InvenTreePart().count( + // Request the number of BOM items + InvenTreePart().count( filters: { "in_bom_for": part.pk.toString(), } - ); + ).then((int value) { + setState(() { + bomCount = value; + }); + }); - variantCount = await InvenTreePart().count( + // Request the number of variant items + InvenTreePart().count( filters: { "variant_of": part.pk.toString(), } - ); + ).then((int value) { + setState(() { + variantCount = value; + }); + }); } - Future _toggleStar() async { + + /* + * Toggle the "star" status of this paricular part + */ + Future _toggleStar(BuildContext context) async { if (InvenTreeAPI().checkPermission("part", "view")) { + showLoadingOverlay(context); await part.update(values: {"starred": "${!part.starred}"}); + hideLoadingOverlay(); refresh(context); } } @@ -168,7 +196,9 @@ class _PartDisplayState extends RefreshableState { icon: FaIcon(part.starred ? FontAwesomeIcons.solidStar : FontAwesomeIcons.star, color: part.starred ? COLOR_STAR : null, ), - onPressed: _toggleStar, + onPressed: () { + _toggleStar(context); + }, ), leading: GestureDetector( child: InvenTreeAPI().getImage(part.thumbnail), diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index a3026430..d03f3904 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -129,11 +129,16 @@ class _StockItemDisplayState extends RefreshableState { }); }); - attachmentCount = await InvenTreeStockItemAttachment().count( + // Request the number of attachments + InvenTreeStockItemAttachment().count( filters: { "stock_item": item.pk.toString() } - ); + ).then((int value) { + setState(() { + attachmentCount = value; + }); + }); // Request information on labels available for this stock item if (InvenTreeAPI().pluginsEnabled()) {