From eee3d2ce61076526d6deab2b89b1818c111b03af Mon Sep 17 00:00:00 2001
From: Peter Ombodi
Date: Mon, 27 Apr 2026 16:02:19 +0300
Subject: [PATCH] fix(mobile): avoid double pop when canceling upload dialog
---
.../upload_action_button.widget.dart | 35 +++++++++++++------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/mobile/lib/presentation/widgets/action_buttons/upload_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/upload_action_button.widget.dart
index e388084c1c..db3b56f03f 100644
--- a/mobile/lib/presentation/widgets/action_buttons/upload_action_button.widget.dart
+++ b/mobile/lib/presentation/widgets/action_buttons/upload_action_button.widget.dart
@@ -33,6 +33,9 @@ class UploadActionButton extends ConsumerWidget {
final isTimeline = source == ActionSource.timeline;
final viewerIntentFilePath = source == ActionSource.viewer ? ref.read(viewIntentFilePathProvider) : null;
List? assets;
+ var isUploadDialogOpen = false;
+ var wasUploadCancelled = false;
+ Future? uploadDialogFuture;
if (source == ActionSource.timeline) {
assets = ref.read(multiSelectProvider).selectedAssets.whereType().toList();
@@ -41,13 +44,20 @@ class UploadActionButton extends ConsumerWidget {
}
ref.read(multiSelectProvider.notifier).reset();
} else {
- unawaited(
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (dialogContext) => const _UploadProgressDialog(),
- ),
- );
+ isUploadDialogOpen = true;
+ uploadDialogFuture =
+ showDialog(
+ context: context,
+ barrierDismissible: false,
+ builder: (dialogContext) => _UploadProgressDialog(
+ onCancel: () {
+ wasUploadCancelled = true;
+ },
+ ),
+ ).whenComplete(() {
+ isUploadDialogOpen = false;
+ });
+ unawaited(uploadDialogFuture);
}
var success = false;
@@ -72,7 +82,7 @@ class UploadActionButton extends ConsumerWidget {
uploadedRemoteAssetId = result.remoteAssetIds.isNotEmpty ? result.remoteAssetIds.first : null;
}
- if (!isTimeline && context.mounted) {
+ if (!isTimeline && context.mounted && isUploadDialogOpen) {
Navigator.of(context, rootNavigator: true).pop();
}
@@ -81,7 +91,7 @@ class UploadActionButton extends ConsumerWidget {
unawaited(ref.read(mainTimelineHandoffProvider).startIfNeeded(origin, remoteAssetId: uploadedRemoteAssetId));
}
- if (context.mounted && !success) {
+ if (context.mounted && !success && !wasUploadCancelled) {
ImmichToast.show(
context: context,
msg: 'scaffold_body_error_occurred'.t(context: context),
@@ -104,7 +114,9 @@ class UploadActionButton extends ConsumerWidget {
}
class _UploadProgressDialog extends ConsumerWidget {
- const _UploadProgressDialog();
+ final VoidCallback onCancel;
+
+ const _UploadProgressDialog({required this.onCancel});
@override
Widget build(BuildContext context, WidgetRef ref) {
@@ -134,7 +146,8 @@ class _UploadProgressDialog extends ConsumerWidget {
onPressed: () {
ref.read(manualUploadCancelTokenProvider)?.complete();
ref.read(manualUploadCancelTokenProvider.notifier).state = null;
- Navigator.of(context).pop();
+ onCancel();
+ Navigator.of(context, rootNavigator: true).pop();
},
labelText: 'cancel'.t(context: context),
),