From 369ae4306274dc1981247c2c8ba006d51487e31c Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 20 Jan 2024 16:28:54 -0500 Subject: [PATCH] Disable app page buttons while app info is being updated --- lib/pages/app.dart | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/pages/app.dart b/lib/pages/app.dart index a11f650..bc0c6ec 100644 --- a/lib/pages/app.dart +++ b/lib/pages/app.dart @@ -23,13 +23,18 @@ class AppPage extends StatefulWidget { class _AppPageState extends State { AppInMemory? prevApp; + bool updating = false; @override Widget build(BuildContext context) { var appsProvider = context.watch(); var settingsProvider = context.watch(); - getUpdate(String id, {bool resetVersion = false}) { - appsProvider.checkUpdate(id).then((e) { + getUpdate(String id, {bool resetVersion = false}) async { + try { + setState(() { + updating = true; + }); + await appsProvider.checkUpdate(id); if (resetVersion) { appsProvider.apps[id]?.app.additionalSettings['versionDetection'] = true; @@ -39,10 +44,14 @@ class _AppPageState extends State { } appsProvider.saveApps([appsProvider.apps[id]!.app]); } - }).catchError((e) { - showError(e, context); - return null; - }); + } catch (err) { + // ignore: use_build_context_synchronously + showError(err, context); + } finally { + setState(() { + updating = false; + }); + } } bool areDownloadsRunning = appsProvider.areDownloadsRunning(); @@ -339,7 +348,7 @@ class _AppPageState extends State { } getResetInstallStatusButton() => TextButton( - onPressed: app?.app == null + onPressed: app?.app == null || updating ? null : () { app!.app.installedVersion = null; @@ -351,7 +360,8 @@ class _AppPageState extends State { )); getInstallOrUpdateButton() => TextButton( - onPressed: (app?.app.installedVersion == null || + onPressed: !updating && + (app?.app.installedVersion == null || app?.app.installedVersion != app?.app.latestVersion) && !areDownloadsRunning ? () async { @@ -398,7 +408,7 @@ class _AppPageState extends State { !isVersionDetectionStandard && !trackOnly) IconButton( - onPressed: app?.downloadProgress != null + onPressed: app?.downloadProgress != null || updating ? null : showMarkUpdatedDialog, tooltip: tr('markUpdated'), @@ -406,7 +416,7 @@ class _AppPageState extends State { if (source != null && source.combinedAppSpecificSettingFormItems.isNotEmpty) IconButton( - onPressed: app?.downloadProgress != null + onPressed: app?.downloadProgress != null || updating ? null : () async { var values = @@ -458,7 +468,7 @@ class _AppPageState extends State { : getInstallOrUpdateButton()), const SizedBox(width: 16.0), IconButton( - onPressed: app?.downloadProgress != null + onPressed: app?.downloadProgress != null || updating ? null : () { appsProvider