|
| 1 | +--- |
| 2 | +title: Scrolling |
| 3 | +description: Overview of Flutter's scrolling support |
| 4 | +--- |
| 5 | + |
| 6 | +Flutter has many built-in widgets that automatically |
| 7 | +scroll and also offers a variety of widgets |
| 8 | +that you can customize to create specific scrolling |
| 9 | +behavior. |
| 10 | + |
| 11 | +## Basic scrolling |
| 12 | + |
| 13 | +Many Flutter widgets support scrolling out of the box |
| 14 | +and do most of the work for you. For example, |
| 15 | +[`SingleChildScrollView`][] automatically scrolls its |
| 16 | +child when necessary. Other useful widgets include |
| 17 | +[`ListView`][] and [`GridView`][]. |
| 18 | +You can check out more of these widgets on the |
| 19 | +[scrolling page][] of the Widget catalog. |
| 20 | + |
| 21 | +<iframe width="560" height="315" src="https://www.youtube.com/embed/DbkIQSvwnZc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
| 22 | + |
| 23 | +<iframe width="560" height="315" src="https://www.youtube.com/embed/KJpkjHGiI5A" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
| 24 | + |
| 25 | +## Infinite scrolling |
| 26 | + |
| 27 | +When you have a long list of items |
| 28 | +in your `ListView` or `GridView` (including an _infinite_ list), |
| 29 | +you can build the items on demand |
| 30 | +as they scroll into view. This provides a much |
| 31 | +more performant scrolling experience. |
| 32 | +For more information, check out |
| 33 | +[`ListView.builder`][] or [`GridView.builder`][]. |
| 34 | + |
| 35 | +[`ListView.builder`]: {{site.api}}/flutter/widgets/ListView/ListView.builder.html |
| 36 | +[`GridView.builder`]: {{site.api}}/flutter/widgets/GridView/GridView.builder.html |
| 37 | + |
| 38 | +### Specialized scrollable widgets |
| 39 | + |
| 40 | +The following widgets provide more specific scrolling |
| 41 | +behavior. |
| 42 | + |
| 43 | +A video on using [`DraggableScrollableSheet`][] |
| 44 | +<iframe width="560" height="315" src="https://www.youtube.com/embed/Hgw819mL_78" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
| 45 | + |
| 46 | +Turn the scrollable area into a wheel! [`ListWheelScrollView`][] |
| 47 | +<iframe width="560" height="315" src="https://www.youtube.com/embed/dUhmWAz4C7Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
| 48 | + |
| 49 | +[`DraggableScrollableSheet`]: {{site.api}}/flutter/widgets/DraggableScrollableSheet-class.html |
| 50 | +[`GridView`]: {{site.api}}/flutter/widgets/GridView-class.html |
| 51 | +[`ListView`]: {{site.api}}/flutter/widgets/ListView-class.html |
| 52 | +[`ListWheelScrollView`]: {{site.api}}/flutter/widgets/ListWheelScrollView-class.html |
| 53 | +[scrolling page]: {{site.url}}/ui/widgets/scrolling |
| 54 | +[`SingleChildScrollView`]: {{site.api}}/flutter/widgets/SingleChildScrollView-class.html |
| 55 | + |
| 56 | +{% comment %} |
| 57 | + Not yet, but coming. Two dimensional scrolling: |
| 58 | + TableView and TreeView. |
| 59 | + Video: https://www.youtube.com/watch?v=UDZ0LPQq-n8 |
| 60 | +{% endcomment %} |
| 61 | + |
| 62 | +## Fancy scrolling |
| 63 | + |
| 64 | +Perhaps you want to implement _elastic_ scrolling, |
| 65 | +also called _scroll bouncing_. Or maybe you want to |
| 66 | +implement other dynamic scrolling effects, like parallax scrolling. |
| 67 | +Or perhaps you want a scrolling header with very specific behavior, |
| 68 | +such as shrinking or disappearing. |
| 69 | + |
| 70 | +You can achieve all this and more using the |
| 71 | +Flutter `Sliver*` classes. |
| 72 | +A _sliver_ refers to a piece of the scrollable area. |
| 73 | +You can define and insert a sliver into a [`CustomScrollView`][] |
| 74 | +to have finer-grained control over that area. |
| 75 | + |
| 76 | +For more information, check out |
| 77 | +[Using slivers to achieve fancy scrolling][] |
| 78 | +and the [Sliver classes][]. |
| 79 | + |
| 80 | +[`CustomScrollView`]: {{site.api}}/flutter/widgets/CustomScrollView-class.html |
| 81 | +[Sliver classes]: {{site.url}}/ui/widgets/layout#Sliver%20widgets |
| 82 | +[Using slivers to achieve fancy scrolling]: {{site.url}}/ui/scrolling/slivers |
| 83 | + |
| 84 | +## Nested scrolling widgets |
| 85 | + |
| 86 | +How do you nest a scrolling widget |
| 87 | +inside another scrolling widget |
| 88 | +without hurting scrolling performance? |
| 89 | +Do you set the `ShrinkWrap` property to true, |
| 90 | +or do you use a sliver? |
| 91 | + |
| 92 | +Check out the "ShrinkWrap vs Slivers" video: |
| 93 | + |
| 94 | +<iframe width="560" height="315" src="https://www.youtube.com/embed/LUqDNnv_dh0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
0 commit comments