Improve the SliverChildBuilderDelegate docs for folk to troubleshoot.#103183
Improve the SliverChildBuilderDelegate docs for folk to troubleshoot.#103183fluttergithubbot merged 2 commits intoflutter:masterfrom
SliverChildBuilderDelegate docs for folk to troubleshoot.#103183Conversation
|
flutter/packages/flutter/lib/src/rendering/sliver_list.dart Lines 279 to 285 in 704bb36 RenderSliverList.performLayout() will create many children to fill up the viewport, so zero-size children may cause an infinite loop.This is hard to catch at runtime, so only be explained through documentation. |
SliverChildBuilderDelegate docs for folk to troubleshot.SliverChildBuilderDelegate docs for folk to troubleshoot.
Piinks
left a comment
There was a problem hiding this comment.
Hey @xu-baolin! Always good to see you. :)
There was a problem hiding this comment.
Is there a way we can catch this and throw an error?
There was a problem hiding this comment.
I've tried both solutions, but neither is perfect.
- Timeout check. When an exception is thrown if time out(about 3 seconds), the Flutter error thread will take about ten seconds(or more) to collect error information (because thousands of children have been created at this time), and the final error message printed to the console will overflow, and the user cannot well informed of what happened;
- When 100 children of zero size are created continuously, throw an exception, which is a bit hacky and maybe misjudged.
Wondering if you have any suggestions?
There was a problem hiding this comment.
Hmm.. you are right, this is very difficult to catch accurately.
We cannot add timeouts (https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#never-check-if-a-port-is-available-before-using-it-never-add-timeouts-and-other-race-conditions), and it is possible the user could have zero sized children in the thousands preceding a child that actually has a size.
There was a problem hiding this comment.
Perhaps we can word it a bit differently, right now it sounds like a warning against this scenario. What should the user do then if they run into this?
Set a child count, return null from builder, or provide children with a size sound like options, what do you think?
There was a problem hiding this comment.
| /// and the [builder] always provide a zero-size widget, such as `Container()` | |
| /// and the [builder] always provides a zero-size widget, such as `Container()` |
There was a problem hiding this comment.
Hmm.. you are right, this is very difficult to catch accurately.
We cannot add timeouts (https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#never-check-if-a-port-is-available-before-using-it-never-add-timeouts-and-other-race-conditions), and it is possible the user could have zero sized children in the thousands preceding a child that actually has a size.
There was a problem hiding this comment.
| /// [builder] always provide a zero size widget, such as `Container()` | |
| /// [builder] always provides a zero size widget, such as `Container()` |
There was a problem hiding this comment.
Perhaps we can word it a bit differently, right now it sounds like a warning against this scenario. What should the user do then if they run into this?
Set a child count, return null from builder, or provide children with a size sound like options, what do you think?
|
@xu-baolin Do you still have plans to follow up on the feedback given above? |
|
I will be back soon! |

Improve some docs for folk to troubleshoot.
Fixes #102904