New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
app bar leading back button should not change if the route is popped #71944
Conversation
if (previouslyImplyLeadingPopButton == null || parentRoute.isActive) { | ||
previouslyImplyLeadingPopButton = parentRoute.canPop; | ||
} | ||
// If the route is not active, it is in the middle of being removed. In |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assert(previouslyImplyLeadingPopupButton != null)
here?
@@ -720,7 +722,15 @@ class _AppBarState extends State<AppBar> { | |||
|
|||
final bool hasDrawer = scaffold?.hasDrawer ?? false; | |||
final bool hasEndDrawer = scaffold?.hasEndDrawer ?? false; | |||
final bool canPop = parentRoute?.canPop ?? false; | |||
if (parentRoute == null) { | |||
previouslyImplyLeadingPopButton = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the objective was to leave the back button alone if a route became inactive (it was popped) and it had a back button before it became inactive? Maybe this should be?
previouslyImplyLeadingPopButton ??= false;
@@ -708,6 +708,8 @@ class _AppBarState extends State<AppBar> { | |||
Scaffold.of(context).openEndDrawer(); | |||
} | |||
|
|||
bool? previouslyImplyLeadingPopButton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this flag ever need to be reset to null?
@@ -708,6 +708,8 @@ class _AppBarState extends State<AppBar> { | |||
Scaffold.of(context).openEndDrawer(); | |||
} | |||
|
|||
bool? previouslyImplyLeadingPopButton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this hadBackButtonWhenRouteWasActive
and include a comment that explains what the variable means when it's null, as well as true/false.
0e8cc82
to
42f369d
Compare
thanks for reviewing, I addressed all comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
There are two issues, the canPop was based on whether the route isFirst or not
bool canPop => !isFirst || willHandlePopInternally
this is inaccurate because a route is no longer the first route when it is popped. The canpop will return true in this case.
but once we fix that we will encounter the second issue: the appbar back button is show when the route.canPop return true.
That means if there are two routes in the history stack, the topmost route canpop return true, and the back button is displayed. As soon as the back button is pressed, the canpop become false. The back button will disappear. Thus I implemented a mechanism to memorize previous decision to show the back button in Appbar if the route is not active.
Related Issues
fixes #67277
Tests
I added the following tests:
see files
Checklist
Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.