auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

[v4.1.0 / v4.2.0] How access child widget on stack router?

Open Sultandi opened this issue 2 years ago • 4 comments

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??

Screenshot from 2022-06-30 09-22-38

Sultandi avatar Jun 30 '22 02:06 Sultandi

@Sultandi I guess I can make a getter for that, but I wonder why would want to access the child?

Milad-Akarie avatar Jul 02 '22 11:07 Milad-Akarie

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?

dannyalder88 avatar Jul 04 '22 08:07 dannyalder88

@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

Sultandi avatar Jul 06 '22 05:07 Sultandi

@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 🙏

marcsanny avatar Jul 08 '22 06:07 marcsanny

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 :)

marcsanny avatar Sep 26 '22 07:09 marcsanny