-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Fix Exception on Nested TabBarView disposal #31581
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
Conversation
|
#31978 merged |
HansMuller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| @override | ||
| void dispose() { | ||
| // Sets `pixels` to a non-null value before `ScrollPosition.dispose` is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a TODO and link to the issue and note once the issue is fix we can remove this workaround
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Description
When a TabBarView is nested in a page of another TabBarView, there will be particular scenarios that will throw an exception.
To reproduce this issue, two conditions must be true:
(ie. current index = 0, tap on tab at index 3 when tab at index 2 has nested TabBarView)
This happens when the framework tries to build
_PagePosition, then dispose of it beforeapplyViewportDimensionhas the chance to be called to setpixelsto a non-null value based on the size of the viewport. This fix adds a flag to determine ifapplyViewportDimensionis invoked beforedispose. If it hasn't been, thendisposewill setpixelsto an arbitrary value before attempting to dispose of it.First exception: This is due to the introduction of #29188, which happens because the initial swap that is necessary for warping causes the nested page that is swapped but not shown to be disposed of before
applyViewportDimensionto be called.Second exception: This one is caused by the animation of the page during warp. The last frame does not build before the second
setStateis called to swap the children back to their original positions, causing the nested page to be built and disposed of beforeapplyViewportDimensioncan be called.TODO:
TabBarViewbuilds its last frame beforesetStateis called to re-swap the children back to their original locations. ScrollPosition.animateTo should build last frame before resolving animation #32054Related Issues
Fixes #18756
Tests
I added the following tests:
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?