无法使用ListView.builder获得所需的滚动-Flutter

时间:2018-07-03 07:57:32

标签: android listview dart flutter

我正在尝试实现一个包含图表和四个项目列表的滚动页面,以便整个页面必须滚动而不是小部件的部分滚动。我使用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快照与当前显示的页面无关。

有人可以告诉我我在上述摘录中所犯的错误吗?如果错误很大或很复杂,请提供必要的代码吗?

1 个答案:

答案 0 :(得分:1)

要停止滚动内部列表,您可以在内部列表视图中使用物理:NeverScrollableScrollPhysics()。这样,他们的个人可滚动性将被删除,它们的行为就像它们是外部列表视图的一部分一样