是否可以在CustomScrollView中使用ListView.builder? [英] Is it possible to use ListView.builder inside of CustomScrollView?
问题描述
是否可以在 CustomScrollView
内使用 ListView.builder
(或类似的东西)?我有这样的 CustomScrollView
:
Is it possible to use ListView.builder
(or something similar) inside of a CustomScrollView
? I have a CustomScrollView
like this:
return Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(...),
SliverList(delegate: SliverChildListDelegate(children))
],
),
);
这很好用,但是在我的实际情况下,列表可能包含成千上万个项目,因此我不想将它们全部传递给 SliverChildListDelegate
.我想使用 ListView.builder
(或类似的东西)在滚动到视图中时构建项目.我期望在 SliverList
或 SliverChildListDelegate
上有一个 .builder
构造函数,但我看不到类似的东西.我想念什么吗?
This works great, but in my actual scenario the list could have thousands of items, so I do not want to pass them all in to SliverChildListDelegate
. I want to use ListView.builder
(or something similar) to build the items as they are scrolled into view. I was expecting there to be a .builder
constructor on either SliverList
or SliverChildListDelegate
but I don't see anything like that. Am I missing something?
推荐答案
SliverList
的 delegate
参数不一定是 SliverChildListDelegate
.
您还可以使用 SliverChildBuilderDelegate
来实现 ListView.builder
SliverList(delegate: SliverChildBuilderDelegate((context, index) {
return Container();
}));
这篇关于是否可以在CustomScrollView中使用ListView.builder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!