auto_route_library
auto_route_library copied to clipboard
[v4.1.0 / v4.2.0] How access child widget on stack router?
Hi,
i have been using this routing library on some previous version (currently using v4.0.1).
but when i run some pub outdate, then trying update the auto_route to version 4.1.0 / 4.2.0, i got issue on this line:
var lastStackWidget = context.topRoute.router.stack.last.child
since the "child" is private variable now (_child => on auto_route v4.1.0 / v4.2.0), how i can access and solve this issue??
@Sultandi I guess I can make a getter for that, but I wonder why would want to access the child?
If it helps with the discussion, I too was accessing page.child when coding a custom route builder that uses AutoRoute.declarative so I could easily create adaptive modal flows with auto_route. Now the child is private it's preventing me from updating the package. The main reason I am doing this is because customRouteBuilder on a CustomRoute has to have a specific const function type so I can't add extra parameters.
My solution was to add overridable getters to the wrapper that the function can read from page.child.
For example:
maxWidth: (page.child as FlowWrapper).maxWidth
There may be a better solution, this is just what I could come up with.
Was there a specific reason child is now private?
@Milad-Akarie : in my coding case its more or less like @dannyalder88 comment. With the custom of modal sheet route, i need to validate another stack router, which is the child / widget itself of topRouter. btw sorry for late reply and thx for ure respond before.
@dannyalder88 : so we must un-cast / validate the wrapper first? but i see in the updated AutoRoutePage code, there is still a possibility the child without the wrapper. * sorry if bad EN
@Milad-Akarie:
Same situation in our project - we were using child and some custom logic to set the back button titles across the app.
Would be really great if there would be a getter that will expose the private _child
variable outside.
Thanks for your reply 🙏
Anyone that want to use child parameter, I created a fork where I exposed it as a getter: https://github.com/marcsanny/auto_route_library.
Also as you can see a pull request was created, so maybe it will be merged by the author :)