I have two ListView with ExpansionTiles that I would like place one after another inside a column which has some other Widgets first inside it. This is my code,
@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()) ] , ) , ) );
}
Using this, widget body shows blank.If I set ListView directly as body, they show up fine. Am I missing something ?
You can wrap your ListView widget inside the Expanded widget and this will allow the ListView to take all the available as long as the Column allows. Note: The main point here is to tell how much tall the ListView will be.
You need to provide Constrained Height to be able to put ListView Widget inside Column Widget. There are many ways of doing it, I am listing a few here. Give one Expanded Widget and other SizedBox. Use a SizedBox Widget For both of them.
Try wrapping your ListView
in Expanded
. It doesn't have an intrinsic height so you need to give it one.
You need to provide constrained height to be able to put ListView
inside Column
. There are many ways of doing it, I am listing few here.
Use Expanded
for both the list
Column( children: <Widget>[ Expanded(child: _list1()), Expanded(child: _list2()), ], )
Give one Expanded
and other SizedBox
Column( children: <Widget>[ Expanded(child: _list1()), SizedBox(height: 200, child: _list2()), ], )
Use SizedBox
for both of them.
Column( children: <Widget>[ SizedBox(height: 200, child: _list1()), SizedBox(height: 200, child: _list2()), ], )
Use Flexible
and you can change flex
property in it, just like Expanded
Column( children: <Widget>[ Flexible(child: _list1()), Flexible(child: _list2()), ], )
If you ListView
is short enough to be able to fit in Column
, use
ListView(shrinkWrap: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With