fix(detail): auto-dismiss "Load remote images" snack bar (#548)
## 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 <agentloop-bot@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/guettli/sharedinbox/pulls/548
This commit was merged in pull request #548.
This commit is contained in:
committed by
guettli
co-authored by
guettli
Agentloop Bot
parent
1e5093b631
commit
8ea5237991
@@ -239,6 +239,10 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
||||
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.',
|
||||
),
|
||||
|
||||
@@ -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.',
|
||||
),
|
||||
|
||||
@@ -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: '<p>Hello <img src="https://example.com/x.png"/></p>',
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
'<p>Hi <img src="https://example.com/x.png"/></p>',
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user