prefer_builder_constructor_for_widget

Group: style

Maturity: stable

Code Sharp v0.0.1

Since info is static, may be stale

View all Lint Rules

Using the Linter

Usually the builder constructor supports lazy loading. This constructor is appropriate for multiple children views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.

BAD:


ListView(
  children: List.generate(10000, (index) => Text('$index')),
)

GOOD:


final children = List.generate(10000, (index) => Text('$index'));
ListView.builder(
  itemCount: children.length,
  itemBuilder: (context, index) => children[index],
)