feat: Add double-back exit confirmation on root screens to prevent accidental app exits - #253
Conversation
Agent-Logs-Url: https://github.com/richardthe3rd/cambridge-beer-festival-app/sessions/f890bcef-de4e-45e1-a325-fe278028ad67 Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/richardthe3rd/cambridge-beer-festival-app/sessions/f890bcef-de4e-45e1-a325-fe278028ad67 Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/richardthe3rd/cambridge-beer-festival-app/sessions/f890bcef-de4e-45e1-a325-fe278028ad67 Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/richardthe3rd/cambridge-beer-festival-app/sessions/fa5e8206-0f61-4350-a9fc-5f2f9ec64125 Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/richardthe3rd/cambridge-beer-festival-app/sessions/fa5e8206-0f61-4350-a9fc-5f2f9ec64125 Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
DateTime.now() returns real wall-clock time in Flutter widget tests, not fake_async time, so the 2-second confirmation window was always seen as within range on the second back press. Replace the timestamp comparison with a dart:async Timer, which is properly controlled by pump(duration) in tests. Also fixes web behaviour: canPop was set to false at the root on web, blocking browser-back navigation. Now canPop: kIsWeb || hasHistory lets the browser handle back normally on web (no exit-confirmation dialog). Fix the snackbar-timeout test: the snackbar duration timer only starts after the enter animation completes, so pump(3s) alone doesn't fire it. Correct sequence: pump(300ms) to finish the enter animation, then pump(3s) to fire the 2s timer, then two pump(250ms) calls to process the exit animation and setState rebuild. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
LCOV of commit
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
🚀 Cloudflare Pages PreviewYour preview deployment is ready! Preview URL: https://copilot-add-go-back-confirma.staging-cambeerfestival.pages.dev This preview will be automatically updated when you push new commits to this PR. |
There was a problem hiding this comment.
Pull request overview
Adds a “double-back to exit” confirmation on root-level screens to reduce accidental app exits on mobile, with accompanying widget tests to validate the behavior.
Changes:
- Wrap
BeerFestivalHomein aPopScopeand implement a 2-second exit confirmation window with aSnackBar. - Add widget tests covering first-back snackbar display, second-back exit request, and behavior after the confirmation window expires.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/main.dart | Adds root back-press interception with a timed confirmation window and optional app-exit trigger. |
| test/main_test.dart | Adds widget tests that simulate back presses and verify snackbar/exit behavior. |
If the user presses back once (starting the confirmation timer) and then navigates deeper via a real pop (didPop=true or canPopNavigation=true), the timer was left active. A subsequent return to root and back press would immediately exit without showing the confirmation snackbar. Cancel and clear _exitConfirmationTimer whenever a real navigation pop occurs in onPopInvokedWithResult. Also add a comment explaining why the 4-pump test sequence is necessary: the snackbar duration timer starts after the enter animation completes (in a separate frame), so a single large pump cannot fire the timer. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🚀 Cloudflare Pages PreviewYour preview deployment is ready! Preview URL: https://copilot-add-go-back-confirma.staging-cambeerfestival.pages.dev This preview will be automatically updated when you push new commits to this PR. |
lib/main.dartandtest/main_test.dart