-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
Fix Exception on Nested TabBarView disposal #31581
Conversation
#31978 merged |
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 beforeapplyViewportDimension
has the chance to be called to setpixels
to a non-null value based on the size of the viewport. This fix adds a flag to determine ifapplyViewportDimension
is invoked beforedispose
. If it hasn't been, thendispose
will setpixels
to 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
applyViewportDimension
to 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
setState
is called to swap the children back to their original positions, causing the nested page to be built and disposed of beforeapplyViewportDimension
can be called.TODO:
TabBarView
builds its last frame beforesetState
is 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?