无法使用ListView.builder获取所需的滚动 - flutter

问题描述 投票:0回答:1

我正在尝试实现一个包含图表和四个项目列表的滚动页面,这样整个页面必须滚动而不是部分滚动窗口小部件。我使用ListView.builder创建了一个滚动列表,并将其作为Column的子项包装在Expanded中。以下是代码:

  @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快照与显示的当前页面无关。

有人可以告诉我我在上面的片段中犯的错误吗?如果错误很大或很复杂,那么请您提供必要的代码吗?

android listview dart flutter
1个回答
1
投票

要停止滚动内部列表,可以在内部列表视图中使用physics:NeverScrollableScrollPhysics()。这样他们的个人可滚动性将被删除,他们将表现得像他们是你的外部列表视图的一部分

© www.soinside.com 2019 - 2024. All rights reserved.