A scrollable, linear list of widgets.

ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. In the cross axis, the children are required to fill the ListView.

If non-null, the itemExtent forces the children to have the given extent in the scroll direction. Specifying an itemExtent is more efficient than letting the children determine their own extent because the scrolling machinery can make use of the foreknowledge of the children's extent to save work, for example when the scroll position changes drastically.

There are three options for constructing a ListView:

  1. The default constuctor takes an explict List of children. This constructor is appropriate for list views with a small number of children because constructing the List requires doing work for every child that could possibly be displayed in the list view instead of just those children that are actually visible.

  2. The ListView.builder takes an IndexedWidgetBuilder, which builds the children on demand. This constructor is appropriate for list views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.

  3. The ListView.custom takes a SliverChildDelegate, which provides the ability to customize additional aspects of the child model. For example, a SliverChildDelegate can control the algorithm used to estimate the size of children that are not actually visible.

See also:

  • SingleChildScrollView, which is a scrollable widget that has a single child.
  • PageView, which is a scrolling list of child widgets that are each the size of the viewport.
  • GridView, which is scrollable, 2D array of widgets.
  • CustomScrollView, which is a scrollable widget that creates custom scroll effects using slivers.
Inheritance

Constructors

ListView({Key key, Axis scrollDirection: Axis.vertical, bool reverse: false, ScrollController controller, bool primary, ScrollPhysics physics, bool shrinkWrap: false, EdgeInsets padding, double itemExtent, List<Widget> children: const [] })

Creates a scrollable, linear array of widgets from an explicit List.

ListView.builder({Key key, Axis scrollDirection: Axis.vertical, bool reverse: false, ScrollController controller, bool primary, ScrollPhysics physics, bool shrinkWrap: false, EdgeInsets padding, double itemExtent, IndexedWidgetBuilder itemBuilder, int itemCount })

Creates a scrollable, linear array of widgets that are created on demand.

ListView.custom({Key key, Axis scrollDirection: Axis.vertical, bool reverse: false, ScrollController controller, bool primary, ScrollPhysics physics, bool shrinkWrap: false, EdgeInsets padding, double itemExtent, SliverChildDelegate childrenDelegate })

Creates a scrollable, linear array of widgets with a custom child model.

Properties

childrenDelegate SliverChildDelegate

A delegate that provides the children for the ListView.

final
itemExtent double

If non-null, forces the children to have the given extent in the scroll direction.

final
controller ScrollController

An object that can be used to control the position to which this scroll view is scrolled.

final, inherited
hashCode int

The hash code for this object.

read-only, inherited
key Key

Controls how one widget replaces another widget in the tree.

final, inherited
padding EdgeInsets

The amount of space by which to inset the children.

final, inherited
physics ScrollPhysics

How the scroll view should respond to user input.

final, inherited
primary bool

Whether this is the primary scroll view associated with the parent PrimaryScrollController.

final, inherited
reverse bool

Whether the scroll view scrolls in the reading direction.

final, inherited
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited
scrollDirection Axis

The axis along which the scroll view scrolls.

final, inherited
shrinkWrap bool

Whether the extent of the scroll view in the scrollDirection should be determined by the contents being viewed.

final, inherited

Methods

buildChildLayout(BuildContext context) Widget

Subclasses should override this method to build the layout model.

debugFillDescription(List<String> description) → void

Add additional information to the given description for use by toString.

build(BuildContext context) Widget

Describes the part of the user interface represented by this widget.

inherited
buildSlivers(BuildContext context) List<Widget>

Subclasses should override this method to build the slivers for the inside of the viewport.

inherited
createElement() StatelessElement

Creates a StatelessElement to manage this widget's location in the tree.

inherited
getDirection(BuildContext context) AxisDirection

Returns the AxisDirection in which the scroll view scrolls.

@protected, inherited
noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() String

Returns a string representation of this object.

inherited
toStringShort() String

A short, textual description of this widget.

inherited

Operators

operator ==(other) bool

The equality operator.

inherited