avoid-shrink-wrap-in-lists
Warns when a ListView
widget with shrinkWrap
parameter is wrapped in a Column
, Row
or another ListView
widget.
According to the Flutter documentation, using shrinkWrap
in lists is expensive performance-wise and should be avoided, since using slivers is significantly cheaper and achieves the same or even better results.
Example
❌ Bad:
Column(
children: [
Expanded(
child: ListView(
// LINT: Avoid passing 'shrinkWrap' to 'ListView' as it can degrade performance. Try using slivers instead.
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: [],
),
),
],
),
✅ Good:
CustomScrollView(
slivers: [
// Correct, uses Sliver instead
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => Container(),
childCount: someObject.length,
),
),
],
),