avoid_shrink_wrap_in_lists
v0.4.0 Warning Widget Best Practices
This rule flags ListView widgets that use shrinkWrap: true. When shrink-wrapping is enabled, the ListView lays out all of its children eagerly to determine its own size, which defeats the lazy rendering that makes scrollable lists performant.
Why use this rule
Section titled “Why use this rule”A ListView with shrinkWrap: true forces Flutter to measure every single child up front, even the ones that are off-screen. For large lists this is extremely expensive and can cause visible jank or even ANRs. The recommended alternative is to use CustomScrollView with SliverList, which gives you the same nested-scrollable layout without the performance cost.
See also: ListView.shrinkWrap | Flutter performance best practices
// ListView with shrinkWrap forces eager layout of all childrenfinal list = ListView(shrinkWrap: true);
final builder = ListView.builder( shrinkWrap: true, itemCount: 10, itemBuilder: (context, index) => Text('$index'),);// ListView without shrinkWrap (default lazy rendering)final list = ListView(children: const [Text('hello')]);
// CustomScrollView with SliverList for nested scroll scenariosfinal scroll = CustomScrollView( slivers: [ SliverList( delegate: SliverChildBuilderDelegate( (context, index) => Text('$index'), childCount: 10, ), ), ],);Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: avoid_shrink_wrap_in_lists: false