Flutter 中 SliverList 与 ListView 的区别

Differences between SliverList vs ListView in Flutter

Flutter中的SliverListListView有什么区别?

几乎没有区别。

ListView 一个SliverList。与 GridView 相同,这是一个 SliverGrid

他们在做同样的事情。它们之间的唯一区别是 SliverList 是条子,而不是小部件。这意味着它在 ScrollView 中使用,通常是 CustomScrollView

ListView 只不过是 SliverList 的出价,将其转换为 Widget,使其可以与 Row/[=21 等其他小部件一起使用=].


大多数情况下,使用 ListView

但是,如果您想要高级滚动行为,例如带滚动的应用栏动画;你需要使用 CustomScrollView。这将迫使您使用 SliverList 而不是 ListView.

根据this article,

All of the scrollable views you use, like ListView and GridView, are actually implemented using Slivers. You can kind of think of Slivers as a lower-level interface, providing finer-grained control on implementing scrollable area. Because slivers can lazily build each item just as it scrolls into view, slivers are particularly useful for efficiently scrolling through large numbers of children.