[PageTransitionsBuilder] ZoomPageTransition causing widget rebuild three times #58345
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 1.19Found to occur in 1.19Found to occur in 1.19frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Description
There's a reproducible demo, try it with https://dartpad.cn/fb30323847b7e0aee6c61bdbecacd060 . It happens on all platforms.
Steps to Reproduce
- Create a
PageRouteBuilderwith_ZoomPageTransition. - Add log to
buildmethod inside new page. - Log printed 3 times total.
Expected results: Build only once.
Actual results: Widget built 3 times.
Logs
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.363
I/flutter ( 7614): State's hashCode: 48367006
I/flutter ( 7614): build: 2020-05-31 12:33:48.365
I/flutter ( 7614): built times: 0
I/flutter ( 7614): built times: 1
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.414
I/flutter ( 7614): State's hashCode: 48367006
I/flutter ( 7614): build: 2020-05-31 12:33:48.422
I/flutter ( 7614): built times: 1
I/flutter ( 7614): built times: 2
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.454
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.467
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.480
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.494
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.507
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.521
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.534
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.548
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.564
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.588
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.602
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.615
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.628
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.643
I/flutter ( 7614): build transition: 2020-05-31 12:33:48.660
I/flutter ( 7614): State's hashCode: 48367006
I/flutter ( 7614): build: 2020-05-31 12:33:48.664
I/flutter ( 7614): built times: 2
I/flutter ( 7614): built times: 3
flutter doctor
[√] Flutter (Channel stable, v1.17.2, on Microsoft Windows [Version 10.0.18363.836], locale zh-CN)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 1.19Found to occur in 1.19Found to occur in 1.19frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Activity
AlexV525 commentedon May 31, 2020
/cc @shihaohong which the transition builder was introduced by #41935 .
[-][PageTransitionsBuilder] ZoomPageTransition causing State create three times[/-][+][PageTransitionsBuilder] ZoomPageTransition causing widget rebuild three times[/+]TahaTesser commentedon Jun 1, 2020
flutter doctor -v
shihaohong commentedon Jun 1, 2020
Hi @AlexVincent525, what sort of issues does this behavior cause for your application?
AlexV525 commentedon Jun 1, 2020
After a short investigation, I found this case would cause the rebuild.
flutter/packages/flutter/lib/src/material/page_transitions_theme.dart
Line 267 in 1d395c5
If comment it out the build situation looks fine, still don't know what happened. The sequence of the
Container,SlideTransition,FadeTransitionhas no affect on this.AlexV525 commentedon Jun 1, 2020
Hi, I just wondering why it would cause three times of build?
Some developer may run into some performance issue with build method, as they don't usually optimize their build method.
shihaohong commentedon Jun 1, 2020
@AlexVincent525 The rebuild is occurring because the widget tree is changing shape due to the changes in transition. Notice that the widget tree could be modified based on whether the animation is moving forwards, backwards, or was interrupted:
The reshaping of the widget tree in this manner triggers a new build of the page.
AlexV525 commentedon Jun 1, 2020
So I guess the reason why the shape changed twice (as I debugged) is because the condition
widget.animation.status == AnimationStatus.forwardand_transitionWasInterruptedusing OR (||) makes the widget tree update? Here they cause the last twobuilds.Can it be improved somehow?
8 remaining items
shihaohong commentedon Jun 3, 2020
Interesting -- It probably has something to do with the timings of the animation of both the scrim appearance, as well as the scale/fade transitions themselves, when the
DualTransitionBuilderwas introduced.Have you tried debugging DualTransitionBuilder or the transition itself to see what might be causing this issue? The ZoomPageTransition was designed earlier than the animations package transitions, so there might be some compatibility issues that need to be resolved.
AlexV525 commentedon Jun 4, 2020
I think it might related to compatibility when there're two
DualTransitionBuilderusing at the same time. Haven't got enough time into it, I'll try to make it looks normal in these days.AlexV525 commentedon Jun 4, 2020
That's definitely related to
reverseBuilder. Still debugging with the builder.AlexV525 commentedon Jun 4, 2020
But that's very simillar with
FadeThroughTransitionin the animations package. See if it can provides some ideas tomorrow.AlexV525 commentedon Jun 4, 2020
Facing a related issue: #39938 . When implement the
_reverseEndScreenScaleTransitionit runs the animation reversely, rather than fade out fast.flutter/packages/flutter/lib/src/material/page_transitions_theme.dart
Lines 167 to 178 in 1d395c5
AlexV525 commentedon Jun 17, 2020
Closing this because the PR has merged.
AlexV525 commentedon Jun 23, 2020
Re-open because the PR has been reverted in #59992 .
Any clues in your investigation? @shihaohong
shihaohong commentedon Jun 24, 2020
From the investigation, it seems like it might be a problem with the test itself, but we are still trying to figure out if it's a problem with the test or the implementation of the PR
AlexV525 commentedon Jun 25, 2020
Oh the one last thing I forgot is that I saw someone updates the AUTHORS file during the PR, does it required something to be in there? Should I update it too? I just found out that I already merged two PRs into flutter. :P
shihaohong commentedon Jun 25, 2020
@AlexVincent525 It's not required, but it allows you to claim credit that you contributed to the Flutter repo! Feel free to add your credentials on there if you'd like to be acknowledged on there :)
github-actions commentedon Aug 19, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.