I am trying to evenly space my list tiles in my list view with the code below and it is not working. The greater objective is to get both scroll and even distribution on rotation. Thanks for the help.
Widget _buildBodyListView() { return new Container( padding: EdgeInsets.all(12.0), child: Container(color: Colors.green, child: ListView(shrinkWrap: false, children: <Widget>[ ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('LATEST NEWS', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET NEWS ', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET REPORT', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('LATEST NEWS', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET NEWS ', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET REPORT', textAlign: TextAlign.center,), ), ], ), ), ); }
You can use the visualDensity property to reduce the space. ListTile( visualDensity: VisualDensity(horizontal: 0, vertical: -4), title: Text("xyz") ); The visualDensity value can be changed from -4.0 to 4.0 . Lower the value, more compact the view.
Wrap your ListTile in a column and use SizedBox to separate list items. Use key in column, not inside ListTile.
As Dinesh has pointed out here, ListTile has received a minLeadingWidth property. Default value is 40 , so to reduce space between leading and title by x pass minLeadingWidth: 40 - x .
I recommend you use the ListView.separated
widget. It has a property called the separatorBuilder
. It return a Widget
, here a SizedBox
of a particular height, that will act as a separator.
Here is how you should do it:
ListView.separated( physics: BouncingScrollPhysics(), shrinkWrap: true, itemCount: 6, itemBuilder: (context, index) => Container( padding: EdgeInsets.all(12.0), child: Container( color: Colors.green, child: ListView( children: const <Widget>[ ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('LATEST NEWS', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET NEWS ', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET REPORT', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('LATEST NEWS', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET NEWS ', textAlign: TextAlign.center,), ), ListTile( trailing: Icon(Icons.keyboard_arrow_right), title: Text('MARKET REPORT', textAlign: TextAlign.center,), ), ], ), ), ), separatorBuilder: (context, index) => SizedBox( height: 10, ) );
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