gpt4 book ai didi

flutter - 单个容器中的多个 listview.builder 方法

转载 作者:IT王子 更新时间:2023-10-29 07:19:54 26 4
gpt4 key购买 nike

我一直在尝试在同一主体容器中显示几个 ListView 。我正在使用 Listview.builder,因为我必须获取 json 数据并显示在 ListView 中。

每个 ListView 都必须从不同的 json 文件中获取数据并垂直显示在前一个 ListView 的下方(是的,就像在嵌套 ListView 中一样)。

我看过嵌套的 listvie 示例但是。是否可以使用 listview.builder ?如果是这样,请向我展示示例或教程链接。谢谢你!

这是我用来创建 ListView 的代码。

ListView.builder(
itemCount: recent == null ? 0 : recent.length,
itemBuilder: (BuildContext context, int index) {
return Column(
children: <Widget>[
Card(
child: Column(
children: <Widget>[
new Image.network(recent[index]["_embedded"]["wp:featuredmedia"][0]["source_url"]),
new Padding(
padding: EdgeInsets.all(10.0),
child: new ListTile(
title: new Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: new Text(recent[index]["title"]["rendered"])),
subtitle: new Text(
recent[index]["excerpt"]["rendered"].replaceAll(new RegExp(r'<[^>]*>'), '')
),
),
)
],
),
)
],
);
},
)
);

最佳答案

您可以通过将 SliverListSliverChildBuilderDelegate 一起使用来实现:

CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
// First JSON
},
childCount: childCount,
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
// Second JSON
},
childCount: childCount,
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
// Third JSON
},
childCount: childCount,
),
),
),
],
);

关于flutter - 单个容器中的多个 listview.builder 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56176327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com