-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix CarouselView crashes when initlal viewportDimension is 0.0 #167271
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 crashes when initlal viewportDimension is 0.0 #167271
Conversation
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
8f9ccf0 to
9d4345d
Compare
|
Golden file changes are available for triage from new commit, Click here to view. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
07a9690 to
0cf2333
Compare
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. Thanks for adding so many test cases!
I think Carousel.weight might also need to be fixed, but it's okay to fix it in a separate PR!
| } | ||
| final double newPixels = getPixelsFromItem(item, flexWeights, itemExtent); | ||
| final double newPixels = | ||
| (viewportDimension == 0.0) ? 0.0 : getPixelsFromItem(item, flexWeights, itemExtent); |
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 move this check in getPixelsFromItem so that we can remove the change in line 1408 as well? Just think it would be better if we move the logic into one method.
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.
Great call! PR updated 🙏
| }; | ||
| _itemExtent = | ||
| _itemExtent == null ? _itemExtent : clampDouble(_itemExtent!, 0, mainAxisExtent); | ||
| widget.itemExtent == null ? null : clampDouble(widget.itemExtent!, 0, mainAxisExtent); |
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.
Just curious, why do we want to have this change here?
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.
Not obvious, but in fact it is crucial to fix this issue.
Without this change, when the viewport dimension is zero at first, _itemExtent is clamped to 0. Later when the viewport gets the final dimension, the old code clampDouble(_itemExtent!, 0, mainAxisExtent); still returns 0.0 and never check again the original widget.itemExtent value.
This is covered by the test named "itemExtent is applied when viewport dimension is updated".
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.
Ah nice catch! Thanks for the explanation!
0cf2333 to
7d908c2
Compare
7d908c2 to
2b155c6
Compare
flutter/flutter@ecabb1a...3ed38e2 2025-04-18 [email protected] Update `led` docs (flutter/flutter#167380) 2025-04-18 [email protected] Throw an error if --local-engine-host is used without --local-engine (flutter/flutter#166948) 2025-04-18 [email protected] Add kotlin compatability to build file validation (flutter/flutter#167143) 2025-04-18 [email protected] Roll Skia from 844496884aa0 to 6c4595124690 (2 revisions) (flutter/flutter#167400) 2025-04-18 [email protected] Fix CarouselView crashes when initlal viewportDimension is 0.0 (flutter/flutter#167271) 2025-04-18 [email protected] Roll Dart SDK from b1eb743f97f5 to ab60afc99bcb (1 revision) (flutter/flutter#167396) 2025-04-18 [email protected] Add InputDecoration.visualDensity and InputDecorationTheme.visualDensity (flutter/flutter#166834) 2025-04-18 [email protected] Roll Skia from acc910544da7 to 844496884aa0 (1 revision) (flutter/flutter#167389) 2025-04-18 [email protected] Roll Skia from a409d685a711 to acc910544da7 (10 revisions) (flutter/flutter#167388) 2025-04-18 [email protected] Roll Dart SDK from 2bb85834e77e to b1eb743f97f5 (2 revisions) (flutter/flutter#167387) 2025-04-18 [email protected] Roll Fuchsia Linux SDK from m8Aln7fTF_8zy1V9N... to MwYckh5OvwwmIYLx0... (flutter/flutter#167385) 2025-04-17 [email protected] Roll Skia from cc2b57434651 to a409d685a711 (3 revisions) (flutter/flutter#167347) 2025-04-17 [email protected] Reduce app startup latency by initializing the engine on a separate thread (flutter/flutter#166918) 2025-04-17 [email protected] Roll Dart SDK from 992221a362ec to 2bb85834e77e (7 revisions) (flutter/flutter#167361) 2025-04-17 [email protected] Added docstring for FilterInput::GetSnapshot (flutter/flutter#167226) 2025-04-17 [email protected] adds Entity docstrings (flutter/flutter#167228) 2025-04-17 [email protected] fixed impeller golden content scale (flutter/flutter#167308) 2025-04-17 [email protected] Added docstring for FilterContents::RenderFilter (flutter/flutter#167227) 2025-04-17 [email protected] Feat: Add equality to NoDefaultCupertinoThemeData (flutter/flutter#166655) 2025-04-17 [email protected] Fix link to engine docs (flutter/flutter#167346) 2025-04-17 [email protected] [macOS] Enable merged platform and UI thread by default (flutter/flutter#166536) 2025-04-17 [email protected] [Windows] Enable merged platform and UI thread by default (flutter/flutter#163726) 2025-04-17 [email protected] Update `CHANGELOG.md` (flutter/flutter#167225) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
….0 (#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 #167271 which addressed the same problem for `CarouselView`. ## Related Issue Fixes #167621 ## Tests Adds 3 tests.
flutter/flutter@ecabb1a...3ed38e2 2025-04-18 [email protected] Update `led` docs (flutter/flutter#167380) 2025-04-18 [email protected] Throw an error if --local-engine-host is used without --local-engine (flutter/flutter#166948) 2025-04-18 [email protected] Add kotlin compatability to build file validation (flutter/flutter#167143) 2025-04-18 [email protected] Roll Skia from 844496884aa0 to 6c4595124690 (2 revisions) (flutter/flutter#167400) 2025-04-18 [email protected] Fix CarouselView crashes when initlal viewportDimension is 0.0 (flutter/flutter#167271) 2025-04-18 [email protected] Roll Dart SDK from b1eb743f97f5 to ab60afc99bcb (1 revision) (flutter/flutter#167396) 2025-04-18 [email protected] Add InputDecoration.visualDensity and InputDecorationTheme.visualDensity (flutter/flutter#166834) 2025-04-18 [email protected] Roll Skia from acc910544da7 to 844496884aa0 (1 revision) (flutter/flutter#167389) 2025-04-18 [email protected] Roll Skia from a409d685a711 to acc910544da7 (10 revisions) (flutter/flutter#167388) 2025-04-18 [email protected] Roll Dart SDK from 2bb85834e77e to b1eb743f97f5 (2 revisions) (flutter/flutter#167387) 2025-04-18 [email protected] Roll Fuchsia Linux SDK from m8Aln7fTF_8zy1V9N... to MwYckh5OvwwmIYLx0... (flutter/flutter#167385) 2025-04-17 [email protected] Roll Skia from cc2b57434651 to a409d685a711 (3 revisions) (flutter/flutter#167347) 2025-04-17 [email protected] Reduce app startup latency by initializing the engine on a separate thread (flutter/flutter#166918) 2025-04-17 [email protected] Roll Dart SDK from 992221a362ec to 2bb85834e77e (7 revisions) (flutter/flutter#167361) 2025-04-17 [email protected] Added docstring for FilterInput::GetSnapshot (flutter/flutter#167226) 2025-04-17 [email protected] adds Entity docstrings (flutter/flutter#167228) 2025-04-17 [email protected] fixed impeller golden content scale (flutter/flutter#167308) 2025-04-17 [email protected] Added docstring for FilterContents::RenderFilter (flutter/flutter#167227) 2025-04-17 [email protected] Feat: Add equality to NoDefaultCupertinoThemeData (flutter/flutter#166655) 2025-04-17 [email protected] Fix link to engine docs (flutter/flutter#167346) 2025-04-17 [email protected] [macOS] Enable merged platform and UI thread by default (flutter/flutter#166536) 2025-04-17 [email protected] [Windows] Enable merged platform and UI thread by default (flutter/flutter#163726) 2025-04-17 [email protected] Update `CHANGELOG.md` (flutter/flutter#167225) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…r#9114) flutter/flutter@ecabb1a...3ed38e2 2025-04-18 [email protected] Update `led` docs (flutter/flutter#167380) 2025-04-18 [email protected] Throw an error if --local-engine-host is used without --local-engine (flutter/flutter#166948) 2025-04-18 [email protected] Add kotlin compatability to build file validation (flutter/flutter#167143) 2025-04-18 [email protected] Roll Skia from 844496884aa0 to 6c4595124690 (2 revisions) (flutter/flutter#167400) 2025-04-18 [email protected] Fix CarouselView crashes when initlal viewportDimension is 0.0 (flutter/flutter#167271) 2025-04-18 [email protected] Roll Dart SDK from b1eb743f97f5 to ab60afc99bcb (1 revision) (flutter/flutter#167396) 2025-04-18 [email protected] Add InputDecoration.visualDensity and InputDecorationTheme.visualDensity (flutter/flutter#166834) 2025-04-18 [email protected] Roll Skia from acc910544da7 to 844496884aa0 (1 revision) (flutter/flutter#167389) 2025-04-18 [email protected] Roll Skia from a409d685a711 to acc910544da7 (10 revisions) (flutter/flutter#167388) 2025-04-18 [email protected] Roll Dart SDK from 2bb85834e77e to b1eb743f97f5 (2 revisions) (flutter/flutter#167387) 2025-04-18 [email protected] Roll Fuchsia Linux SDK from m8Aln7fTF_8zy1V9N... to MwYckh5OvwwmIYLx0... (flutter/flutter#167385) 2025-04-17 [email protected] Roll Skia from cc2b57434651 to a409d685a711 (3 revisions) (flutter/flutter#167347) 2025-04-17 [email protected] Reduce app startup latency by initializing the engine on a separate thread (flutter/flutter#166918) 2025-04-17 [email protected] Roll Dart SDK from 992221a362ec to 2bb85834e77e (7 revisions) (flutter/flutter#167361) 2025-04-17 [email protected] Added docstring for FilterInput::GetSnapshot (flutter/flutter#167226) 2025-04-17 [email protected] adds Entity docstrings (flutter/flutter#167228) 2025-04-17 [email protected] fixed impeller golden content scale (flutter/flutter#167308) 2025-04-17 [email protected] Added docstring for FilterContents::RenderFilter (flutter/flutter#167227) 2025-04-17 [email protected] Feat: Add equality to NoDefaultCupertinoThemeData (flutter/flutter#166655) 2025-04-17 [email protected] Fix link to engine docs (flutter/flutter#167346) 2025-04-17 [email protected] [macOS] Enable merged platform and UI thread by default (flutter/flutter#166536) 2025-04-17 [email protected] [Windows] Enable merged platform and UI thread by default (flutter/flutter#163726) 2025-04-17 [email protected] Update `CHANGELOG.md` (flutter/flutter#167225) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…r#9114) flutter/flutter@ecabb1a...3ed38e2 2025-04-18 [email protected] Update `led` docs (flutter/flutter#167380) 2025-04-18 [email protected] Throw an error if --local-engine-host is used without --local-engine (flutter/flutter#166948) 2025-04-18 [email protected] Add kotlin compatability to build file validation (flutter/flutter#167143) 2025-04-18 [email protected] Roll Skia from 844496884aa0 to 6c4595124690 (2 revisions) (flutter/flutter#167400) 2025-04-18 [email protected] Fix CarouselView crashes when initlal viewportDimension is 0.0 (flutter/flutter#167271) 2025-04-18 [email protected] Roll Dart SDK from b1eb743f97f5 to ab60afc99bcb (1 revision) (flutter/flutter#167396) 2025-04-18 [email protected] Add InputDecoration.visualDensity and InputDecorationTheme.visualDensity (flutter/flutter#166834) 2025-04-18 [email protected] Roll Skia from acc910544da7 to 844496884aa0 (1 revision) (flutter/flutter#167389) 2025-04-18 [email protected] Roll Skia from a409d685a711 to acc910544da7 (10 revisions) (flutter/flutter#167388) 2025-04-18 [email protected] Roll Dart SDK from 2bb85834e77e to b1eb743f97f5 (2 revisions) (flutter/flutter#167387) 2025-04-18 [email protected] Roll Fuchsia Linux SDK from m8Aln7fTF_8zy1V9N... to MwYckh5OvwwmIYLx0... (flutter/flutter#167385) 2025-04-17 [email protected] Roll Skia from cc2b57434651 to a409d685a711 (3 revisions) (flutter/flutter#167347) 2025-04-17 [email protected] Reduce app startup latency by initializing the engine on a separate thread (flutter/flutter#166918) 2025-04-17 [email protected] Roll Dart SDK from 992221a362ec to 2bb85834e77e (7 revisions) (flutter/flutter#167361) 2025-04-17 [email protected] Added docstring for FilterInput::GetSnapshot (flutter/flutter#167226) 2025-04-17 [email protected] adds Entity docstrings (flutter/flutter#167228) 2025-04-17 [email protected] fixed impeller golden content scale (flutter/flutter#167308) 2025-04-17 [email protected] Added docstring for FilterContents::RenderFilter (flutter/flutter#167227) 2025-04-17 [email protected] Feat: Add equality to NoDefaultCupertinoThemeData (flutter/flutter#166655) 2025-04-17 [email protected] Fix link to engine docs (flutter/flutter#167346) 2025-04-17 [email protected] [macOS] Enable merged platform and UI thread by default (flutter/flutter#166536) 2025-04-17 [email protected] [Windows] Enable merged platform and UI thread by default (flutter/flutter#163726) 2025-04-17 [email protected] Update `CHANGELOG.md` (flutter/flutter#167225) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…r#9114) flutter/flutter@ecabb1a...3ed38e2 2025-04-18 [email protected] Update `led` docs (flutter/flutter#167380) 2025-04-18 [email protected] Throw an error if --local-engine-host is used without --local-engine (flutter/flutter#166948) 2025-04-18 [email protected] Add kotlin compatability to build file validation (flutter/flutter#167143) 2025-04-18 [email protected] Roll Skia from 844496884aa0 to 6c4595124690 (2 revisions) (flutter/flutter#167400) 2025-04-18 [email protected] Fix CarouselView crashes when initlal viewportDimension is 0.0 (flutter/flutter#167271) 2025-04-18 [email protected] Roll Dart SDK from b1eb743f97f5 to ab60afc99bcb (1 revision) (flutter/flutter#167396) 2025-04-18 [email protected] Add InputDecoration.visualDensity and InputDecorationTheme.visualDensity (flutter/flutter#166834) 2025-04-18 [email protected] Roll Skia from acc910544da7 to 844496884aa0 (1 revision) (flutter/flutter#167389) 2025-04-18 [email protected] Roll Skia from a409d685a711 to acc910544da7 (10 revisions) (flutter/flutter#167388) 2025-04-18 [email protected] Roll Dart SDK from 2bb85834e77e to b1eb743f97f5 (2 revisions) (flutter/flutter#167387) 2025-04-18 [email protected] Roll Fuchsia Linux SDK from m8Aln7fTF_8zy1V9N... to MwYckh5OvwwmIYLx0... (flutter/flutter#167385) 2025-04-17 [email protected] Roll Skia from cc2b57434651 to a409d685a711 (3 revisions) (flutter/flutter#167347) 2025-04-17 [email protected] Reduce app startup latency by initializing the engine on a separate thread (flutter/flutter#166918) 2025-04-17 [email protected] Roll Dart SDK from 992221a362ec to 2bb85834e77e (7 revisions) (flutter/flutter#167361) 2025-04-17 [email protected] Added docstring for FilterInput::GetSnapshot (flutter/flutter#167226) 2025-04-17 [email protected] adds Entity docstrings (flutter/flutter#167228) 2025-04-17 [email protected] fixed impeller golden content scale (flutter/flutter#167308) 2025-04-17 [email protected] Added docstring for FilterContents::RenderFilter (flutter/flutter#167227) 2025-04-17 [email protected] Feat: Add equality to NoDefaultCupertinoThemeData (flutter/flutter#166655) 2025-04-17 [email protected] Fix link to engine docs (flutter/flutter#167346) 2025-04-17 [email protected] [macOS] Enable merged platform and UI thread by default (flutter/flutter#166536) 2025-04-17 [email protected] [Windows] Enable merged platform and UI thread by default (flutter/flutter#163726) 2025-04-17 [email protected] Update `CHANGELOG.md` (flutter/flutter#167225) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…er#167271) ## Description This PR fixes CarouselView crashes due to viewportDimension being 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. ## Related Issue Fixes flutter#163436 Fixes flutter#160679 ## Tests Adds 5 tests.
….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 crashes due to viewportDimension being 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.
Related Issue
Fixes #163436
Fixes #160679
Tests
Adds 5 tests.