You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CupertinoSheet example broken state with programmatic pop #175390
Hi @justinmc@MitchellGoodwin, I've taken a look at the source code and have some feedback. We have a PopScope widget that closes the sheet when the user attempts to pop the last page.
However, this works only when the back button is used, as in that case didPop will be false. When we use Navigator.of(context).pop(), the route is getting popped, and didPop is true. If I remove the check for didPop, we end up with a weird UI:
bad_example.mov
For now, I don't know a way to prevent the route pop after Navigator.of(context).pop() call.
What I suggest is updating the example app. There is no canPop() check before calling pop(). You may similarly break any app by simply calling Navigator.of(context).pop() while you are on the initial route.
To prevent the issue, we can add an explicit canPop check like the following:
CupertinoButton.filled(
onPressed: () {
final navigator =Navigator.of(context);
if (navigator.canPop()) {
navigator.pop();
} else {
CupertinoSheetRoute.popSheet(context);
}
},
child:constText('Go Back'),
),
For now, I don't know a way to prevent the route pop after Navigator.of(context).pop() call.
What I suggest is updating the example app. There is no canPop() check before calling pop(). You may similarly break any app by simply calling Navigator.of(context).pop() while you are on the initial route.
I agree that it's simpler to update the example app. But I think you can get the same result by just replacing navigator.pop() with navigator.maybePop().
For now, I don't know a way to prevent the route pop after Navigator.of(context).pop() call.
What I suggest is updating the example app. There is no canPop() check before calling pop(). You may similarly break any app by simply calling Navigator.of(context).pop() while you are on the initial route.
I agree that it's simpler to update the example app. But I think you can get the same result by just replacing navigator.pop() with navigator.maybePop().
We could definitely use maybePop to omit popping the initial page, but then the sheet will remain open, and tapping on Go Back will have no effect. Or may I miss something?
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
tirth-patel-nc commentedon Sep 16, 2025
@justinmc thanks for the report. Most likely this is dupe of #171878 (comment). Labelling it for team's tracking.
ksokolovskyi commentedon Sep 19, 2025
Hi @justinmc @MitchellGoodwin, I've taken a look at the source code and have some feedback. We have a
PopScopewidget that closes the sheet when the user attempts to pop the last page.flutter/packages/flutter/lib/src/cupertino/sheet.dart
Lines 179 to 188 in 7ade3f3
However, this works only when the back button is used, as in that case
didPopwill be false. When we useNavigator.of(context).pop(), the route is getting popped, anddidPopis true. If I remove the check fordidPop, we end up with a weird UI:bad_example.mov
For now, I don't know a way to prevent the route pop after
Navigator.of(context).pop()call.What I suggest is updating the example app. There is no
canPop()check before callingpop(). You may similarly break any app by simply callingNavigator.of(context).pop()while you are on the initial route.To prevent the issue, we can add an explicit
canPopcheck like the following:example.mov
What do you think?
MitchellGoodwin commentedon Sep 19, 2025
I agree that it's simpler to update the example app. But I think you can get the same result by just replacing
navigator.pop()withnavigator.maybePop().ksokolovskyi commentedon Sep 19, 2025
We could definitely use
maybePopto omit popping the initial page, but then the sheet will remain open, and tapping onGo Backwill have no effect. Or may I miss something?MitchellGoodwin commentedon Sep 19, 2025
The sheet will close.
maybePopwill hit PopScope with a didPop of false.ksokolovskyi commentedon Sep 19, 2025
Indeed, thanks a lot for the explanation! I was always thinking that
maybePopjust checkscanPopand then callspop.rkishan516 commentedon Sep 21, 2025
@ksokolovskyi you're changing this, or can i go ahead and change?
ksokolovskyi commentedon Sep 21, 2025
@rkishan516, if you are ready to work on this issue, feel free to take it. Thanks!
rkishan516 commentedon Sep 21, 2025
Sure, let me make initial change then.
fix: cupertino sheet broken example with programatic pop (#175709)
fix: cupertino sheet broken example with programatic pop (flutter#175709
github-actions commentedon Oct 8, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.fix: cupertino sheet broken example with programatic pop (flutter#175709