如何在列中放入两个ListView?

kar*_* vs 18 flutter

我有两个带有ExpansionTiles的ListView,我希望一个接一个地放在一个列中,其中首先包含一些其他Widgets.这是我的代码,

 @override
 Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
    appBar: new AppBar(
        title: new Text("Project Details"),
        backgroundColor: Colors.blue[800]),
    body:

    new Padding(padding: new EdgeInsets.all(10.0),
      child: new Column(children: <Widget>[
        new Text(project.name, style: new TextStyle(
            fontWeight: FontWeight.bold,
            color: Colors.blue[700],
            fontSize: 15.0
        )),
        new RowMaker("District", project.district),
        new RowMaker("River", project.river),
        new RowMaker("Tac Approved", project.tacApproved),
        new RowMaker("Func Sanctioned", project.fundSanctioned),
        new Row(children: <Widget>[
          new FlatButton(onPressed: null,
            color: Colors.blue,
            child: new Text("Gallery"),
            textColor: Colors.white,),
          new FlatButton(onPressed: null,
              color: Colors.blue,
              child: new Text("Upload Images"),
              textColor: Colors.white),
          new FlatButton(
              onPressed: null,
              color: Colors.blue,
              child: new Text("Update"),
              textColor: Colors.white),
        ],),
        new ListView(children: getSfListTiles()),
        new ListView(children: getWorkStatementTiles())


    ]
        ,
      )
      ,
    )
);
Run Code Online (Sandbox Code Playgroud)

}

使用它,小部件主体显示空白.如果我将ListView直接设置为正文,它们会显示正常.我错过了什么吗?

Col*_*son 38

尝试包装你ListViewExpanded.它没有固有的高度所以你需要给它一个.


Cop*_*oad 15

您需要提供约束高度能够把ListView里面Column。有很多方法可以做到这一点,我在这里列出了一些。

  1. 使用Expanded两个列表

    Column(
      children: <Widget>[
        Expanded(child: _list1()),
        Expanded(child: _list2()),
      ],
    )
    
    Run Code Online (Sandbox Code Playgroud)
  2. 给一个Expanded和另一个SizedBox

    Column(
      children: <Widget>[
        Expanded(child: _list1()),
        SizedBox(height: 200, child: _list2()),
      ],
    )
    
    Run Code Online (Sandbox Code Playgroud)
  3. 使用SizedBox对他们俩的。

    Column(
      children: <Widget>[
        SizedBox(height: 200, child: _list1()),
        SizedBox(height: 200, child: _list2()),
      ],
    )
    
    Run Code Online (Sandbox Code Playgroud)
  4. 使用Flexible,您可以更改其中的flex属性,就像Expanded

    Column(
      children: <Widget>[
        Flexible(child: _list1()),
        Flexible(child: _list2()),
      ],
    )
    
    Run Code Online (Sandbox Code Playgroud)
  5. 如果您ListView足够矮,可以适应Column,请使用

    ListView(shrinkWrap: true)
    
    Run Code Online (Sandbox Code Playgroud)