Skip to content

feat: Add double-back exit confirmation on root screens to prevent accidental app exits - #253

Merged
richardthe3rd merged 7 commits into
mainfrom
copilot/add-go-back-confirmation
May 11, 2026
Merged

feat: Add double-back exit confirmation on root screens to prevent accidental app exits#253
richardthe3rd merged 7 commits into
mainfrom
copilot/add-go-back-confirmation

Conversation

Copilot AI commented May 11, 2026

Copy link
Copy Markdown
Contributor
  • Review existing back-exit behavior and current tests in lib/main.dart and test/main_test.dart
  • Add widget test for second back press after confirmation window expiry (should not exit)
  • Verify snackbar prompt appears again after timeout
  • Attempt to run relevant tests and summarize results/constraints
  • Refine timeout test assertion based on review feedback

@richardthe3rd richardthe3rd changed the title Add double-back exit confirmation on root screens to prevent accidental app exits feat: Add double-back exit confirmation on root screens to prevent accidental app exits May 11, 2026
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>
@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

LCOV of commit 6d54af9 during CI #147

Summary coverage rate:
  lines......: 77.1% (2439 of 3163 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate:
                                                      |Lines       |Functions  |Branches    
  Filename                                            |Rate     Num|Rate    Num|Rate     Num
  ==========================================================================================
  lib/main.dart                                       | 0.0%    103|    -     0|    -      0

@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/main.dart 94.59% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Cloudflare Pages Preview

Your 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.

@richardthe3rd
richardthe3rd marked this pull request as ready for review May 11, 2026 09:24
Copilot AI review requested due to automatic review settings May 11, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BeerFestivalHome in a PopScope and implement a 2-second exit confirmation window with a SnackBar.
  • 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.

Comment thread lib/main.dart
Comment thread test/main_test.dart
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>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Cloudflare Pages Preview

Your 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.

@richardthe3rd
richardthe3rd merged commit c700b1c into main May 11, 2026
11 checks passed
@richardthe3rd
richardthe3rd deleted the copilot/add-go-back-confirmation branch May 11, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants