Can't add a ListView in Flutter

后端 未结 3 1161
遇见更好的自我
遇见更好的自我 2020-12-18 04:04

I am trying to write an App using Flutter, but every time I add a ListView, the following exception is thrown at runtime: Vertical viewport was given unbounded height<

相关标签:
3条回答
  • 2020-12-18 04:23

    Just wrap the ListView with Expanded widget.

    new Expanded(
    child: new ListView(
              .....
              )
    );
    

    This tells the ListView to take width and height as much as it can.

    0 讨论(0)
  • 2020-12-18 04:25

    Just Wrap into Container and give it an height

    new Container(
      height: 44.0,
      child: new ListView(
        scrollDirection: Axis.horizontal,
        children: <Widget>[
          new RaisedButton(
            onPressed: null,
            child: new Text("Facebook"),
          ),
          new Padding(padding: new EdgeInsets.all(5.00)),
          new RaisedButton(
            onPressed: null,
            child: new Text("Google"),
          )
        ],
      ),
    )
    
    0 讨论(0)
  • 2020-12-18 04:39

    You can fix the exception by specifying shrinkWrap = true for your ListView.

    ListView(
      shrinkWrap: true,
      children...
    )
    

    This is stated in the exception message. The reason is stated in the exception messag as well.

    In this specific case I am not particularly sure which Widget in the tree causes this, but I think that it is not relevant. I do not know what your Container about the ListView is about. I would start by wrapping it around the Column, but shrinkWrap should do the trick.

    0 讨论(0)
提交回复
热议问题