text stringlengths 1 372 |
|---|
interactive example |
<code_start> |
import 'package:flutter/material.dart'; |
void main() { |
runApp( |
MyApp( |
items: List<String>.generate(10000, (i) => 'item $i'), |
), |
); |
} |
class MyApp extends StatelessWidget { |
final List<String> items; |
const MyApp({super.key, required this.items}); |
@override |
widget build(BuildContext context) { |
const title = 'long list'; |
return MaterialApp( |
title: title, |
home: scaffold( |
appBar: AppBar( |
title: const text(title), |
), |
body: ListView.builder( |
itemCount: items.length, |
prototypeItem: ListTile( |
title: text(items.first), |
), |
itemBuilder: (context, index) { |
return ListTile( |
title: text(items[index]), |
); |
}, |
), |
), |
); |
} |
} |
<code_end> |
<topic_end> |
<topic_start> |
children’s extent |
to specify each item’s extent, you can use either itemExtent or prototypeItem. |
specifying either 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. |
<topic_end> |
<topic_start> |
scrolling |
flutter has many built-in widgets that automatically |
scroll and also offers a variety of widgets |
that you can customize to create specific scrolling |
behavior. |
<topic_end> |
<topic_start> |
basic scrolling |
many flutter widgets support scrolling out of the box |
and do most of the work for you. for example, |
SingleChildScrollView automatically scrolls its |
child when necessary. other useful widgets include |
ListView and GridView. |
you can check out more of these widgets on the |
scrolling page of the widget catalog. |
<topic_end> |
<topic_start> |
infinite scrolling |
when you have a long list of items |
in your ListView or GridView (including an infinite list), |
you can build the items on demand |
as they scroll into view. this provides a much |
more performant scrolling experience. |
for more information, check out |
ListView.builder or GridView.builder. |
<topic_end> |
<topic_start> |
specialized scrollable widgets |
the following widgets provide more specific scrolling |
behavior. |
a video on using DraggableScrollableSheet |
turn the scrollable area into a wheel! ListWheelScrollView |
<topic_end> |
<topic_start> |
fancy scrolling |
perhaps you want to implement elastic scrolling, |
also called scroll bouncing. or maybe you want to |
implement other dynamic scrolling effects, like parallax scrolling. |
or perhaps you want a scrolling header with very specific behavior, |
such as shrinking or disappearing. |
you can achieve all this and more using the |
flutter sliver* classes. |
a sliver refers to a piece of the scrollable area. |
you can define and insert a sliver into a CustomScrollView |
to have finer-grained control over that area. |
for more information, check out |
using slivers to achieve fancy scrolling |
and the sliver classes. |
<topic_end> |
<topic_start> |
nested scrolling widgets |
how do you nest a scrolling widget |
inside another scrolling widget |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.