-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
fix: Check active entries on parent navigator for hasActiveRouteBelow
#146428
fix: Check active entries on parent navigator for hasActiveRouteBelow
#146428
Conversation
11abed4
to
9e722c6
Compare
@chunhtai Can you have a look? |
(Triage) Hey @VictorOhashi it looks like there are some failing checks here, can you take a look? |
89c6b9c
to
1e86a53
Compare
7d505ef
to
f13fd5b
Compare
Fixed |
@@ -3790,6 +3816,11 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res | |||
@override | |||
void didChangeDependencies() { | |||
super.didChangeDependencies(); | |||
final NavigatorState? parentNavigator = context.findAncestorStateOfType<NavigatorState>(); |
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.
This won't trigger rebuild when it changes
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.
How to proper get the NavigatorState?
Can be something like this?
NavigatorState? get _parentNavigator => context.findAncestorStateOfType<NavigatorState>();
or there are some InheritedWidget that expose the NavigatorState?
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.
There is currently no way to listen for navigator changes as this pr is the first time that we expose property that requires navigator look up.
/// Whether there is at least one active route underneath this route. | ||
@protected | ||
bool get hasActiveRouteBelow { | ||
if (_navigator == null) { | ||
return false; | ||
} | ||
|
||
final bool hasActiveParentRouteBelow = _hasActiveParentRouteBelow(_navigator!._parentNavigator); |
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.
in nested case, it seem weird that you tap the inner appbar but then the outer navigator gets pop. I think this behavior may have different expectation based on use case.
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.
If we have one structure like this:
- MaterialApp
- Navigator (MainShellRoute)
- MainScreen
- Navigator (AnotherShellRoute)
- AnotherScreen
- Navigator (MainShellRoute)
When AnotherScreen is popped, since his parent Navigator (AnotherShellRoute) don't have any child page it should be popped as well, no?
And what would you recommend to do in cases where we have multiple Navigators?
Today my work around is force adding a BackButton to every page that can't include it auto, which for me is not desirable.
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.
As a user I would expect the back button should only pop content in the area that it surrounds. If AnotherShellRoute
only taken part of the screen and there isn't a route in AnotherShellRoute
to be popped, there shouldn't be a back button in AnotherShellRoute
.
It would be a different story if MainScreen is just an empty container and AnotherShellRoute
take up the whole screen though, but in that case why would you need the MainShellRoute in the first place?
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.
This is also why I am hesitating on this approach. I worry people may have different expectation based on their use cases
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.
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 as a user felt a bit weird about if there is a back button on page1 and press it pop the entire page includes the sidebar, but I do understand people may have special UX requirement. In this case, I think you should have a special backbutton implement in your code base to handle this use case.
This is just my opinion though, so I may be wrong. but as of now, I am not confident moving forward with this pr since we are just 2 data points. We can revisit this if we have more people asking to change or preserve this behavior.
WDYT?
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.
Fine for me
This should fix cases when we have nested navigators.
Fix: #144687
Pre-launch Checklist
///
).