Skip to content

fix: sign-out crash from disposed drawer context#6811

Open
dawidvdh wants to merge 1 commit intoBasedHardware:mainfrom
dawidvdh:fix/5652-signout-crash
Open

fix: sign-out crash from disposed drawer context#6811
dawidvdh wants to merge 1 commit intoBasedHardware:mainfrom
dawidvdh:fix/5652-signout-crash

Conversation

@dawidvdh
Copy link
Copy Markdown

@dawidvdh dawidvdh commented Apr 18, 2026

Summary

  • The sign-out handler called navigator.pop() to close the drawer
    before showDialog, disposing the drawer's context
  • showDialog then used the dead context, causing either a silent failure or crash
  • Fix: show the confirmation dialog while the drawer is still mounted, pop both dialog and drawer on confirm

Closes #5652

I am not a flutter developer so this could be totally wrong but I was exploring this cool project and thought, ah lets try fix something minor, excuse and close if this is just noise.

@dawidvdh dawidvdh marked this pull request as ready for review April 18, 2026 08:39
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 18, 2026

Greptile Summary

This PR fixes a crash on sign-out by reordering the drawer close and dialog show operations. Previously, navigator.pop() disposed the drawer's BuildContext before it was passed to showDialog, causing a silent failure or crash; now the dialog is shown while the drawer is still mounted, and both the dialog and drawer are dismissed inside the confirm callback.

Confidence Score: 5/5

Safe to merge — correctly fixes a real crash with no regressions introduced.

The fix is minimal, targeted, and uses the correct Flutter pattern (show dialog while parent context is still mounted, dismiss both in the confirm callback). The only remaining note is a pre-existing P2 around the context.mounted guard always evaluating to false after the drawer pop, which likely has no practical impact if the app uses a Firebase auth-state listener for post-sign-out navigation.

No files require special attention.

Important Files Changed

Filename Overview
app/lib/pages/settings/settings_drawer.dart Fixes sign-out crash by showing the confirmation dialog before popping the drawer, then popping dialog and drawer in sequence on confirm; a minor pre-existing issue with context.mounted always being false after the drawer pop is noted.

Sequence Diagram

sequenceDiagram
    participant User
    participant Drawer
    participant Dialog
    participant AuthService

    Note over Drawer: Before fix (broken)
    User->>Drawer: tap Sign Out
    Drawer->>Drawer: navigator.pop() → context disposed ❌
    Drawer->>Dialog: showDialog(context: disposed_ctx) → crash/silent fail

    Note over Drawer: After fix
    User->>Drawer: tap Sign Out
    Drawer->>Dialog: showDialog(context: valid_ctx) ✅
    User->>Dialog: tap Confirm
    Dialog->>Dialog: Navigator.of(ctx).pop() — close dialog
    Dialog->>Drawer: Navigator.of(context).pop() — close drawer
    Dialog->>AuthService: SharedPreferencesUtil().clear()
    Dialog->>AuthService: AuthService.instance.signOut()
    Dialog->>Drawer: if (context.mounted) routeToPage(...) — likely false
Loading

Comments Outside Diff (1)

  1. app/lib/pages/settings/settings_drawer.dart, line 496-501 (link)

    P2 context.mounted guard likely always false after drawer pop

    Navigator.of(context).pop() closes the drawer synchronously, after which context (the drawer's BuildContext) becomes unmounted. By the time await SharedPreferencesUtil().clear() and await AuthService.instance.signOut() complete, context.mounted will be false, so routeToPage(context, const AppShell(), replace: true) never executes.

    This was already broken in the original code (the drawer was popped before showDialog was even called), so sign-out navigation likely relies on a Firebase auth-state listener rather than this call. If that's the case this is just dead code worth noting. If the app does depend on this routeToPage call to navigate after sign-out, you'd need to capture the parent navigator before the drawer opens (e.g. final rootNavigator = Navigator.of(context, rootNavigator: true)) and use it here instead.

Reviews (1): Last reviewed commit: "fix: show sign-out dialog before closing..." | Re-trigger Greptile

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.

Bug: context.mounted crash in settings_drawer.dart after sign-out

1 participant