-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix CarouselView.weighted crashes when initlal viewportDimension is 0.0 #167628
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 CarouselView.weighted crashes when initlal viewportDimension is 0.0 #167628
Conversation
QuncCccccc
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.
NICE fix! LGTM. Thank you!
| // (with weight 7), we leave some space before item 0 assuming there is another | ||
| // item -1 as the first visible item. | ||
| int get _firstVisibleItemIndex { | ||
| if (constraints.viewportMainAxisExtent == 0.0) { |
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 we add a code comment to simply explain why we want to add this check here and below? Something like, If constraints.viewportMainAxisExtent is 0, firstChildExtent will be 0 and cause division error.
34d3a36 to
168d2d9
Compare
….0 (flutter#167628) ## Description This PR fixes `CarouselView.weigthed` crashes due to given constraints being zero (which happen, for instance, when viewportDimension is 0.0). At startup, a warm-up frame can be produced before the Flutter engine has reported the initial view metrics. As a result, the first frame can be produced with a size of zero. In the context of CarouselView this leads to some problems mainly related to division by zero. Similar to flutter#167271 which addressed the same problem for `CarouselView`. ## Related Issue Fixes flutter#167621 ## Tests Adds 3 tests.
Description
This PR fixes
CarouselView.weigthedcrashes due to given constraints being zero (which happen, for instance, when viewportDimension is 0.0).At startup, a warm-up frame can be produced before the Flutter engine has reported the
initial view metrics. As a result, the first frame can be produced with a size of zero. In the context of CarouselView this leads to some problems mainly related to division by zero.
Similar to #167271 which addressed the same problem for
CarouselView.Related Issue
Fixes #167621
Tests
Adds 3 tests.