From a337c3fda3be5571f3539d72879d48cd93a15938 Mon Sep 17 00:00:00 2001 From: bvandeusen Date: Thu, 12 Mar 2026 21:01:01 -0400 Subject: [PATCH] Fix update dialog: show errors, handle OpenFile result correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Check OpenResult.type before resetting state — previously a failed open_file call (e.g. installer blocked on emulator) silently called state = const UpdateState(), nulling latestVersion and downloadUrl, causing "Version null" and a non-functional Download button - Show errorMessage in dialog with error colour so failures are visible - Guard Download button on downloadUrl != null (no button if URL lost) Co-Authored-By: Claude Sonnet 4.6 --- lib/app.dart | 14 ++++++++++++-- lib/providers/update_provider.dart | 14 ++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 2992b77..ef50671 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -185,7 +185,7 @@ class _ShellState extends ConsumerState<_Shell> { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Version ${state.latestVersion} is ready to install.'), + Text('Version ${state.latestVersion ?? '?'} is ready to install.'), if (state.currentVersion != null) Text( 'Installed: v${state.currentVersion}', @@ -205,6 +205,16 @@ class _ShellState extends ConsumerState<_Shell> { style: Theme.of(context).textTheme.bodySmall, ), ], + if (state.status == UpdateStatus.error && + state.errorMessage != null) ...[ + const SizedBox(height: 12), + Text( + state.errorMessage!, + style: Theme.of(context).textTheme.bodySmall?.copyWith( + color: Theme.of(context).colorScheme.error, + ), + ), + ], ], ), actions: [ @@ -212,7 +222,7 @@ class _ShellState extends ConsumerState<_Shell> { onPressed: () => Navigator.pop(dialogContext), child: const Text('Later'), ), - if (!isDownloading) + if (!isDownloading && state.downloadUrl != null) FilledButton( onPressed: () => ref .read(updateProvider.notifier) diff --git a/lib/providers/update_provider.dart b/lib/providers/update_provider.dart index 6ef3473..73dbdcc 100644 --- a/lib/providers/update_provider.dart +++ b/lib/providers/update_provider.dart @@ -119,14 +119,20 @@ class UpdateNotifier extends Notifier { }, ); - await OpenFile.open( + final result = await OpenFile.open( path, type: 'application/vnd.android.package-archive', ); - // Transition to idle — the system installer is now open. - // Going back to `available` would re-trigger the update dialog loop. - state = const UpdateState(); + if (result.type == ResultType.done) { + // Installer launched — reset to idle so the dialog closes naturally. + state = const UpdateState(); + } else { + state = state.copyWith( + status: UpdateStatus.error, + errorMessage: 'Could not open installer: ${result.message}', + ); + } } catch (e) { state = state.copyWith( status: UpdateStatus.error,