Skip to content
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

Merged
merged 3 commits into from Jan 6, 2021

Conversation

chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Dec 8, 2020

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Dec 8, 2020
@google-cla google-cla bot added the cla: yes label Dec 8, 2020
if (previouslyImplyLeadingPopButton == null || parentRoute.isActive) {
previouslyImplyLeadingPopButton = parentRoute.canPop;
}
// If the route is not active, it is in the middle of being removed. In
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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.

@chunhtai
Copy link
Contributor Author

thanks for reviewing, I addressed all comments.

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The back button appears for a few moments while I replace a route with Navigator 2.0.
3 participants