Skip to content
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

[Question] How do I access the previous child in buildTransition? #183

Open
laynor opened this issue Mar 2, 2022 · 0 comments
Open

[Question] How do I access the previous child in buildTransition? #183

laynor opened this issue Mar 2, 2022 · 0 comments

Comments

@laynor
Copy link

laynor commented Mar 2, 2022

I'm working on a kinda large flutter app, and we're using vrouter as our routing solution. So far it served us well, but we're now encountering some issues when it comes to implementing our custom transitions.
The design asks for a transition where the old page (or subpage, as we also use VNester) is animated as well as the new page.
For example, one of our transitions works as follows:

  1. old content is faded out, until the (portion of) the screen becomes white (opacity 1 to 0)
  2. new content is faded in (opacity 0 to 1)

Another transition we want to implement switches the old content with the new content with some sort of sliding transition: the old content slides left disappearing from the screen, the new content appears from the right as if they were placed side by side.
This looks like the rightToLeftJoined transition in the page_transition package: https://youtu.be/q-e5t3qnB_M?t=58

I've been able to implement 1 using a FadeTransition with a VWidgetGuard child in the VNester.widgetBuilder definition, and interacting with the animation controller in the beforeLeave and afterEnter functions in VWidgetGuard.

                  VNester(
                    path: null,
                    widgetBuilder: (body) {
                                 ....
                                 FadeTransition(
                                    opacity: Tween<double>(begin: 1.0, end: 0.0).animate(animationController),
                                    child: VWidgetGuard(
                                        beforeLeave: (r, p) async {
                                          await animationController.forward();
                                        },
                                        afterEnter: (ctx, _, __) async {
                                          await animationController.reverse();
                                        },
                                        child: body),
                                  )
               }

Ideally, I'd prefer using the buildTransition attribute of VNester/VRouter to specify the transitions, but I do not have access to the previous value of body.
Is there a cleaner way to implement these transitions, or would you consider passing the previous value of body to the buildTransition method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant