【发布时间】:2018-12-11 11:02:54
【问题描述】:
我正在尝试实现一个包含图表和四个项目列表的滚动页面,这样整个页面必须滚动而不是小部件的部分滚动。我使用 ListView.builder 创建了一个滚动列表,并将其包装在 Expanded 作为 Column 的子项中。 以下是代码:
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Column(
children: <Widget>[
new Container(
width: 490.0,
height: 340.0,
child: new LineChart(),
),
new Expanded(
//height: 500.0,
child: new ListView.builder(
itemBuilder: (_, int index) {
return new Row(
children: <Widget>[
//displays list details
Contents(this.details[index]),
],
);
},
itemCount: this.details.length,
),
),
],
),
);
}
The output for the above snippet
因此,为了实现完全滚动,我在 ListView.builder 本身中包含了我的类(创建以显示列表详细信息)。运行程序后,我获得了整页滚动,但为 ListView 中的每个项目创建了一个单独的图表。我意识到“itemCount”已应用于两个小部件。 以下是代码:
@override
Widget createListView(BuildContext context, AsyncSnapshot snapshot) {
return new ListView.builder(
itemCount: this.details.length,
itemBuilder: (BuildContext context, int index) {
return new Column(
children: <Widget>[
new Container(
width: 490.0,
height: 340.0,
child: LineChart(),
),
//displays list details
Contents(this.details[index]),
new Divider(height: 2.0,),
],
);
},
);
}
The output for the above snippet
P.S.:AsyncSnapshot 快照与显示的当前页面无关。
有人可以告诉我我在上面的 sn-ps 中犯的错误吗?如果错误很大或很复杂,请您提供必要的代码吗?
【问题讨论】:
标签: android listview dart flutter