From 8ea5237991d8234001cce83125cd59aeb008c7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bot=20of=20Thomas=20G=C3=BCttler?= Date: Mon, 8 Jun 2026 21:59:49 +0200 Subject: [PATCH] fix(detail): auto-dismiss "Load remote images" snack bar (#548) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - The "Load remote images" snack bar in single-mail view (and the analogous thread view) never disappeared on its own — the user had to interact with it. - Flutter's `SnackBar` defaults to `persist: true` whenever an `action` is provided (see `flutter/lib/src/material/snack_bar.dart`: `persist = persist ?? action != null`), which short-circuits the duration-based dismiss timer in `ScaffoldMessengerState.build`: ```dart _snackBarTimer = Timer(snackBar.duration, () { if (snackBar.persist) return; // <-- here hideCurrentSnackBar(reason: SnackBarClosedReason.timeout); }); ``` So the explicit `duration: 3s` was set, but the "View" action made the snack bar persistent and the timer's callback returned early. - Pass `persist: false` explicitly on both snack bars so the 3-second timer fires and the snack bar slides away on its own, while the "View" action button still works to navigate to the trusted-senders settings. ## Test plan - [x] Added widget regression test in `test/widget/email_detail_screen_test.dart` (`Load remote images snack bar auto-dismisses after 3 seconds`). - [x] Added analogous test in `test/widget/thread_detail_screen_test.dart`. - [x] `task test-widget` — all 174 widget tests pass. - [x] `scripts/run_unit_tests.sh` — all 552 unit tests pass. - [x] `fvm dart analyze --fatal-infos` on changed files — no issues. - [x] `fvm dart format` — no diffs. - [ ] Manual: open a single mail with HTML body from an untrusted sender; tap "Load remote images"; verify the snack bar appears, images load, and the snack bar disappears after ~3 seconds while the "View" action button still navigates to `/accounts/trusted-senders` when tapped. Closes #484 Co-authored-by: Agentloop Bot Reviewed-on: https://codeberg.org/guettli/sharedinbox/pulls/548 --- lib/ui/screens/email_detail_screen.dart | 4 ++ lib/ui/screens/thread_detail_screen.dart | 4 ++ test/widget/email_detail_screen_test.dart | 48 +++++++++++++++++++ test/widget/thread_detail_screen_test.dart | 54 ++++++++++++++++++++++ 4 files changed, 110 insertions(+) diff --git a/lib/ui/screens/email_detail_screen.dart b/lib/ui/screens/email_detail_screen.dart index 59097be..5a2d3b2 100644 --- a/lib/ui/screens/email_detail_screen.dart +++ b/lib/ui/screens/email_detail_screen.dart @@ -239,6 +239,10 @@ class _EmailDetailScreenState extends ConsumerState { ScaffoldMessenger.of(ctx).showSnackBar( SnackBar( duration: const Duration(seconds: 3), + // SnackBar defaults to persist=true when an action + // is set, which disables the auto-dismiss timer. + // Explicitly opt back into duration-based dismiss. + persist: false, content: const Text( 'Images will be loaded automatically for this sender.', ), diff --git a/lib/ui/screens/thread_detail_screen.dart b/lib/ui/screens/thread_detail_screen.dart index 9c0351f..6058aa0 100644 --- a/lib/ui/screens/thread_detail_screen.dart +++ b/lib/ui/screens/thread_detail_screen.dart @@ -214,6 +214,10 @@ class _EmailMessageCardState extends ConsumerState<_EmailMessageCard> { ScaffoldMessenger.of(context).showSnackBar( SnackBar( duration: const Duration(seconds: 3), + // SnackBar defaults to persist=true when an + // action is set, which disables auto-dismiss. + // Explicitly opt into duration-based dismiss. + persist: false, content: const Text( 'Images will be loaded automatically for this sender.', ), diff --git a/test/widget/email_detail_screen_test.dart b/test/widget/email_detail_screen_test.dart index b7237bd..677ff0a 100644 --- a/test/widget/email_detail_screen_test.dart +++ b/test/widget/email_detail_screen_test.dart @@ -582,6 +582,54 @@ void main() { expect(find.textContaining('Structure not available'), findsOneWidget); }); + + testWidgets( + 'Load remote images snack bar auto-dismisses after 3 seconds', + (tester) async { + const body = EmailBody( + emailId: 'acc-1:42', + htmlBody: '

Hello

', + attachments: [], + ); + await tester.pumpWidget( + buildApp( + initialLocation: + '/accounts/acc-1/mailboxes/INBOX/emails/acc-1%3A42', + overrides: _overrides(body: body), + ), + ); + await tester.pumpAndSettle(); + + // The "Load remote images" button is visible because the sender is + // not yet trusted. + expect(find.text('Load remote images'), findsOneWidget); + + await tester.tap(find.text('Load remote images')); + // Settle the snack bar enter animation and the setState rebuild + // that swaps in the image-loading WebView. + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + // Snack bar must be visible. + expect( + find.text('Images will be loaded automatically for this sender.'), + findsOneWidget, + ); + + // After 3 seconds (the snack bar's duration) plus the reverse + // animation, the snack bar must be gone. + // Regression test for #484: SnackBar with an action defaults to + // persist=true, which disables auto-dismiss — explicit persist:false + // restores duration-based dismissal. + await tester.pump(const Duration(seconds: 4)); + await tester.pumpAndSettle(); + + expect( + find.text('Images will be loaded automatically for this sender.'), + findsNothing, + ); + }, + ); }); } diff --git a/test/widget/thread_detail_screen_test.dart b/test/widget/thread_detail_screen_test.dart index e61f19d..63b6e61 100644 --- a/test/widget/thread_detail_screen_test.dart +++ b/test/widget/thread_detail_screen_test.dart @@ -249,5 +249,59 @@ void main() { expect(find.text('Body content here'), findsOneWidget); }); + + testWidgets( + 'Load remote images snack bar auto-dismisses after 3 seconds', + (tester) async { + final email = _threadEmail(); + await tester.pumpWidget( + buildApp( + initialLocation: '/accounts/acc-1/mailboxes/INBOX/threads/thread-1', + overrides: [ + accountRepositoryProvider.overrideWithValue( + FakeAccountRepository([kTestAccount]), + ), + mailboxRepositoryProvider.overrideWithValue( + FakeMailboxRepository(), + ), + emailRepositoryProvider.overrideWithValue( + FakeEmailRepository( + emails: [email], + emailBody: const EmailBody( + emailId: 'acc-1:10', + htmlBody: + '

Hi

', + attachments: [], + ), + ), + ), + ], + ), + ); + await tester.pumpAndSettle(); + + expect(find.text('Load remote images'), findsOneWidget); + + await tester.tap(find.text('Load remote images')); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + expect( + find.text('Images will be loaded automatically for this sender.'), + findsOneWidget, + ); + + // Regression test for #484: SnackBar with an action defaults to + // persist=true, which disables auto-dismiss — explicit persist:false + // restores duration-based dismissal. + await tester.pump(const Duration(seconds: 4)); + await tester.pumpAndSettle(); + + expect( + find.text('Images will be loaded automatically for this sender.'), + findsNothing, + ); + }, + ); }); }