简体   繁体   English

如何让 Widget 在 Flutter Web 上不溢出 ListView

[英]How to make Widget not overflow ListView on Flutter Web

Context : I'm trying to make a web app with Flutter - so this is all in Chrome上下文:我正在尝试使用 Flutter 制作一个网络应用程序 - 所以这一切都在 Chrome 中

Problem : I have a chart, from the charts_flutter library, and it renders OK when inside a Column.问题:我有一个来自charts_flutter库的图表,它在列内呈现正常。 The issue is that I want to be able to scroll and add more content below the chart.问题是我希望能够滚动并在图表下方添加更多内容。 When I try changing the column to a ListView, it overflows (seems the Chart is trying to be as big as possible and the ListView has infinite height).当我尝试将列更改为 ListView 时,它溢出(似乎 Chart 试图尽可能大并且 ListView 具有无限高度)。 I'm not sure how to get around this issue.我不知道如何解决这个问题。

Current Code : Just the scaffold, because that's all that I think is important here当前代码只是脚手架,因为这就是我认为在这里很重要的所有内容

Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: ListView(
        children: <Widget>[
          Row(
            children: <Widget>[
              FlatButton(onPressed: (){
                print("flat button pressed");
              }, child: Text("Flat Button 1")),
              FlatButton(onPressed: (){
                print("flat button pressed");
              }, child: Text("Flat Button 2")),
              FlatButton(onPressed: (){
                print("flat button pressed");
              }, child: Text("Flat Button 3")),
            ],
            mainAxisAlignment: MainAxisAlignment.center,
          ),
          Flexible(child: GroupedStackedBarChart.withRandomData()),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );

buddy just wraps your Listview with Expanded and Expand your widget with Column like this: buddy 只是用Expanded包装你的Listview并用Column像这样扩展你的小部件:

body: Column(
        children: <Widget>[
          Expanded( 
            child: ListView(
              children: <Widget>[

              ],
            ),
          ),

I think the Flexible causes the chart to fill the parent's height, which is infinite.我认为Flexible会导致图表填充父级的高度,这是无限的。 Try wrapping it in a Column instead to give a pre-calculated size.尝试将其包装在Column以提供预先计算的大小。

body: ListView(
    children: <Widget>[
      Row(
        children: <Widget>[
          FlatButton(onPressed: (){
            print("flat button pressed");
          }, child: Text("Flat Button 1")),
          FlatButton(onPressed: (){
            print("flat button pressed");
          }, child: Text("Flat Button 2")),
          FlatButton(onPressed: (){
            print("flat button pressed");
          }, child: Text("Flat Button 3")),
        ],
        mainAxisAlignment: MainAxisAlignment.center,
      ),
      Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [GroupedStackedBarChart.withRandomData()],
      ),
    ],
  ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM