Repository navigation
fix: close only the dialog's own route when open turns false - #37
Merged
AdamMusa merged 2 commits intoOct 29, 2026
Merged
Conversation
The Material BottomSheet and both AlertDialog renderers closed with a blind Navigator.pop() inside build. An open: false that arrived before the route was pushed popped the user's page and left _open stuck, so the control could never reopen; when another route covered the dialog, that route was popped instead; and popping during build threw. This restores the route ownership of 0a4511eb (lost when the engine was extracted) in a shared widgets-layer helper: the route is pushed after the frame and remembered per control, a close before the push completes the lifecycle instead, and closing pops or removes only that route. Every presentation fires exactly one dismiss and can be reopened. The sheet now pushes the same ModalBottomSheetRoute showModalBottomSheet builds so it owns the route.
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Engine-only fix with no Ruby change. Follow-up found during Package D (D1 #17, D3 #29).
Bug
The Material
BottomSheetand bothAlertDialogrenderers (Material and Cupertino) closed themselves with a blindNavigator.of(context).pop()called synchronously insidebuild.canPop(); the sheet had no guard at all.openwas already false, but left_open: truebehind.Consequences, all reproduced by the new test with the dialog on the second page of a nested navigator:
open: falsebefore the route is pushed (same frame asopen: true): the alert dialogs pop the user's page, and_openstays true, so the control can never reopen. Nodismissis fired, so Ruby keeps tracking the dialog.open: falsewhile another route covers the dialog (all three renderers): the route above is popped instead of the dialog.buildthrowssetState() or markNeedsBuild() called during build.This is a regression of the owner's fix 0a4511eb ("Fix bottom sheet route closing"). It exists only in AdamMusa/ruflet, in the old
ruflet_client/flet_packages/flet, and was the final state of that file before the client was deleted (68ba6952). The engine was extracted from an earlier copy, so the fix was lost. It is not in ruflet-engine or ruflet-template history. That commit made the sheet stateful: it tracked the sheet's ownModalRoute, deferred the pop to a post-frame callback, handled a close requested while still opening, and fireddismissonce the route completed.Fix: the same route-ownership approach, shared
New neutral helper
lib/src/widgets/control_route.dart(widgets layer only, so it imports neither Material nor Cupertino):presentControlRoute(context, control, createRoute)sets_openand pushes the route onto the owning navigator after the frame. It remembers the route per control in anExpando. Ifopenwas turned off again first, or the control left the tree, nothing is pushed and the lifecycle completes:_open/openare reset anddismissfires, so Ruby untracks the dialog and it can be reopened.closeControlRoute(control)runs after the frame and closes only that control's route:pop()when it is on top,removeRoute()when something covers it. If the route is not presented yet, the pending presentation handles the close. Repeated rebuilds while closing do nothing.dismiss, through the route'spoppedfuture, as before.Per renderer:
alert_dialog.dart/cupertino_alert_dialog.dart: same routes (ControlMaterialDialogRoute/ControlCupertinoDialogRoute, so the 1f21fca live-barrier behaviour is kept). Present and close now go through the helper.bottom_sheet.dart: pushes the sameModalBottomSheetRoutethatshowModalBottomSheetbuilds, with identical arguments (capturedThemes, scrim label/tap hint, theme barrier-color fallback). This lets the control own the route object. The parity is proven by a guard test that passes on both the oldshowModalBottomSheetcode and the new code.The iOS
BottomSheet(cupertino_bottom_sheet.dart) has the same bug on this base. It is fixed by D1 (#17) with the same ownership pattern and covered by its tests (close while animating in, reopen, nested-navigator rebuilds), so it is left untouched here to avoid conflicts. Once both PRs merge, D1/D3 can be folded onto this helper in a small refactor.Tests
test/widgets/dialog_early_close_test.dartcovers the Cupertino AlertDialog (iOS), the Material AlertDialog and the Material BottomSheet (Android). Each case mounts the dialog on page 2 of a nested navigator:open: falselands before the route is pushed (a post-frame callback ahead of the control's own). Expected: no route popped (page 2 survives,canPoptrue), no exception,open == false, exactly onedismiss, and reopen works.open: falsewhile the route is still animating in. Expected: only the dialog closes, onedismiss, reopen works.open: falsewhile another route is pushed above the dialog, plus an extra rebuild. Expected: the route above survives, onedismiss, back to page 2 with no dialog, reopen works.A guard test checks that the Material sheet keeps the
showModalBottomSheetpresentation: aModalBottomSheetRoutein the owning navigator,Scrimlabel, dismissible, drag, safe area,bgcolor, handle and barrier color, and a barrier tap that fires onedismiss.verify_pr.sh(Flutter 3.41.2; Ruby tree = cleanorigin/mainb34072be because Ruby is unchanged):Ruby usage (unchanged API, now reliable)