Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the margin between 'leading' and 'title' for ListTile ? Flutter

Tags:

The margin between leading and title is too much;

enter image description here

How to decrease it; I have tried several ways:

  1. warp the leading with container and set margin right negative;
  2. warp the title and set padding-left

however, it does not work at all; is there any solution, i do need help

like image 356
zhouwangsheng Avatar asked Nov 26 '18 02:11

zhouwangsheng


People also ask

How do you reduce the gap between leading and title in ListTile flutters?

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 .

How do you reduce the space between ListTile flutters?

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.


2 Answers

you're ultimately better off building your own containers - there's nothing special or complicated about ListTile. that way you can easily customize things like the spacing between a title and a button. just use something like so:

  Container(     padding: new EdgeInsets.symmetric(vertical: 6.0, horizontal: 6.0),     margin: EdgeInsets.symmetric(vertical: 6.0),      decoration: BoxDecoration(       borderRadius: BorderRadius.circular(6.0),       border: Border.all(color: Colors.black),     ),      child: Column(       children: <Widget>[         Row(           mainAxisAlignment: MainAxisAlignment.start,           children: <Widget>[                    IconButton(                     icon: Icon(myLeadingIcon),                     onPressed: () => {},                   ),                   Padding(padding: EdgeInsets.only(left: 20.0)),                   Text(_myTitle),                 ],               ),     ... 
like image 128
blaneyneil Avatar answered Sep 19 '22 16:09

blaneyneil


The only answer that worked for me is to Matrix transform the title widget.

Here, the title text padding is decreased by 16.

ListTile(   leading: Icon(icon),   title: Transform(               transform: Matrix4.translationValues(-16, 0.0, 0.0),               child: Text("Title text",                           style: TextStyle(fontSize: 18, color: textPrimary)),               ), ); 

Source: How to set the padding between leading and title from Flutter ListTile?

like image 23
Ray Li Avatar answered Sep 18 '22 16:09

Ray Li