Overview
ListView is a scrollable list of controls arranged linearly. It is the most commonly used scrolling control and displays its children one after another in the scroll direction. In the cross axis, the children are required to fill the ListView. ListView is very efficient and can handle thousands of items through lazy rendering whenbuild_controls_on_demand is enabled.
Basic Example
Class Definition
Properties
controls
A list of controls to display inside ListView. Controls are arranged linearly in the scroll direction.
horizontal
Whether to layout the controls horizontally.
False(default) - Vertical scrolling listTrue- Horizontal scrolling list
reverse
Whether the scroll view scrolls in the reading direction.
-
If the reading direction is left-to-right and
horizontalisTrue, the scroll view scrolls from left to right whenreverseisFalseand from right to left whenreverseisTrue. -
If
horizontalisFalse, the scroll view scrolls from top to bottom whenreverseisFalseand from bottom to top whenreverseisTrue.
spacing
The height (or width when
horizontal is True) of the divider between the controls, in pixels.When divider_thickness is 0, this creates empty space. When divider_thickness is greater than 0, this determines the divider height.item_extent
A fixed height or width (when
horizontal is True) of an item to optimize rendering.When all items have the same size, setting this property improves scrolling performance significantly.This property has effect only when
build_controls_on_demand is True or spacing is 0.first_item_prototype
Whether the dimensions of the first item of
controls should be used as a “prototype” for all other items.When True, all items will have the same height (or width if horizontal) as the first item, which can improve performance.prototype_item
A control to be used as a “prototype” for all items. All items will have the same height (or width if horizontal) as the prototype.
This property has effect only when
build_controls_on_demand is True or spacing is 0.divider_thickness
If greater than
0, a Divider is used as spacing between list view items.The thickness of the divider line. The spacing property determines the total height allocated for the divider.padding
The amount of space by which to inset the children.Can be a single number for uniform padding, or use
ft.padding.all(), ft.padding.symmetric(), or ft.padding.only() for more control.clip_behavior
How to clip the controls.Options:
ClipBehavior.HARD_EDGE- Clip with hard edgesClipBehavior.ANTI_ALIAS- Clip with anti-aliasingClipBehavior.ANTI_ALIAS_WITH_SAVE_LAYER- Clip with anti-aliasing and save layerClipBehavior.NONE- No clipping
semantic_child_count
The number of children that will contribute semantic information for accessibility.Useful when the actual number of children is different from the semantic count.
cache_extent
Items that fall in the cache area (before or after the visible area) are laid out even though they are not yet visible on screen.The
cache_extent describes how many pixels the cache area extends before the leading edge and after the trailing edge of the viewport.The total extent covered is: cache_extent before + main axis extent + cache_extent after.A larger cache extent improves scrolling smoothness but uses more memory.build_controls_on_demand
Whether the controls should be built lazily/on-demand.When
True (default), controls are only rendered when they’re about to become visible. This is particularly useful when dealing with a large number of controls and dramatically improves performance.Layout Behavior
How Children Are Arranged
-
Scroll Direction: Children are arranged linearly in the scroll direction (vertical by default, horizontal if
horizontalisTrue). - Cross Axis: Children fill the entire width (in vertical mode) or height (in horizontal mode).
-
Spacing: The
spacingproperty adds gaps between items. -
Lazy Rendering: When
build_controls_on_demandisTrue, only visible items (plus cache area) are rendered.
Scrolling
ListView inherits fromScrollableControl and is scrollable by default. You can control scrolling behavior:
Examples
Basic Vertical List
Horizontal Scrolling List
List with Dividers
Large List with Fixed Item Height
List with Padding
Reverse Order List
Chat-Style List
Performance Optimization
For Large Lists
When working with thousands of items:- Enable lazy rendering: Keep
build_controls_on_demand=True(default) - Set fixed item size: Use
item_extentorfirst_item_prototype - Adjust cache extent: Use smaller values to reduce memory usage
Use Cases
- Contact Lists: Display user contacts with avatars and details
- Chat Messages: Show conversation history
- News Feeds: Display articles or posts
- Settings Menus: Create scrollable settings pages
- Product Catalogs: Show products in a list
- Horizontal Galleries: Create horizontal image galleries