Closed noga-dev closed 2 years ago
Also would be good to have a history of the stack with the ability to go back and forth like in Routemaster.
The first binding works in GoRouter after two attempts
During the first, the navigator is not build yet (since the building of the builder
happens before the building of the Navigator
). During the second, the building happens in the same order but the Navigator
has been build the first time, hence the success.
The second one just throws
This is because the context
that is given to you is too high up the tree to fetch InheritedGoRouter
(which is the widget used to get GoRouter
). The solution is for GoRouter.of
to detect the case where the context
is too high and return the right result. @csells you might want to check what Provider
does. However this will be a bit harder and will necessitate a bit of refactoring because RouterDelegate
is such a bad object to work with (this refactoring would be the same as the one explained in this issue, killing two birds with one stone.
Also would be good to have a history of the stack with the ability to go back and forth like in Routemaster.
I have much to say about this but you should open another issue since this has nothing to do with your first question :)
By wrapping the MaterialApp's builder's child with CallbackShortcut and passing various options of popping route, like
Navigator.of(context)
or
context.pop()
or
GoRouterDelegate
or
_goRouter.pop()
or
Router.of(context).routerDelegate.popRoute()
etc.
I get exceptions like
Router operation requested with a context that does not include a Router.
and
No GoRouter found in context
.Only thing that seems to kind of work is appRouter.navigator?.pop(), and that requires 2 attempts after the first time. With Auto Route it's enough to call
_autoRoute.pop()
from anywhere in the app using a shortcut of my choosing for it to pop the closest encompassing route.Can the same not be done in GoRouter?
Example of my latest draft of MaterialApp
To reiterate, the first binding works in GoRouter after two attempts, the second one just throws. But it does work in Auto Route with no problems.