Closed Miiite closed 2 years ago
Remove tabBar's onTap and add a listener to the controller itself. Preserve the state of the views by reusing the keys in the routes.
Ideally GoRoute should have the option to override the current location instead of forcing us to go through the primitive, potentially buggy and boilerplate-y, route of navigating and preserving states. @csells can we introduce a 'overrideCurrentLocation(string newRoute)'?
Remove tabBar's onTap and add a listener to the controller itself. Preserve the state of the views by reusing the keys in the routes.
Ideally GoRoute should have the option to override the current location instead of forcing us to go through the primitive, potentially buggy and boilerplate-y, route of navigating and preserving states. @csells can we introduce a 'overrideCurrentLocation(string newRoute)'?
I don't think adding à listener to the controller is solving anything, I might be missing something, but I think it introduces its own set of unwanted behaviors when calling the "go" method.
But I like the idea of overriding the current location a lot.
context.push()
and nested navigation should work just fine together. Check out the books example.
Hello,
I am facing a nested navigation scenario that requires me to "push" child pages, instead of using
GoRouter.go
. The children widgets (equivalent to thePerson
widget in the example project) are used in multiple pages, and are unaware of the current context. So it requires me to push the widget onto the navigation stack, no matter where the user is right now in the app.So if I update the nested_navigation.dart sample file with this kind of changes, it looks like this:
The only things that changed, is that now I
push
the Person page on click, and therefore I declared a/person/xx
route in the Router declaration.The issue with that scenario is that, when the user swipes left and right in the TabBar, the index of the current tabbar changes, but GoRouter is unaware of those changes, so the URL stays the same.
/family/f1
.Addams
family, but my URL is stillfamily/f1
.Wednesday
. So I nowpush
the/person/p4
onto the navigation stack/family/f1/person/p4
which does not exist.It looks like we are missing a way of "synchronising" the GoRouter URL with the currently displayed screen. In my scenario, I would need a way to tell GoRouter that the URL is now
family/f2
when the user swipes right.My first reaction was to add a
GoRouter.go
call, when the user swipes, by reacting to the Controller events. But If I do that, when I will trigger "deeplink" navigation by calling for examplecontext.go('/family/f3/person/p2')
, then after this URL will be interpreted and the screen loaded, the family's page Controller will trigger a value change, so I will trigger aGoRouter.go
call to try to synchronise my screen's state with GoRouter's state, and that will make me go back to/family/f3
.It's not necessarily an easy problem to describe, so I hope I am making sense here.
Thanks for the help !