Remove padding from ListTile between leading and title
I need to remove some padding between leading Widget and title Widget in a ListTile. It has too much blank spaces. Is there a way to do that? The code that I am using for that is this:
ListTile _getActionMenu(String text, IconData icon, Function() onTap) {
return new ListTile(
leading: new Icon(icon),
title: new Text(text),
onTap: onTap,
);
}
You can use Align
and specify the Alignment
.
ListTile _getActionMenu(String text, IconData icon, Function() onTap) {
return new ListTile(
leading: new Icon(icon),
title: Align(
child: new Text(text),
alignment: Alignment(-1.2, 0),
),
onTap: onTap,
);
}
EDIT: After Flutter 2.0 upgrade
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
.
Align
results will depend on text and tile width.
Use Transform.translate
for consistent results.
ListTile(
leading: Icon(icon),
title: Transform.translate(
offset: Offset(-16, 0),
child: Text('Some text'),
),
);
You can use the minLeadingWidth on your ListTile. The default value is 40, so you can use a lower value to make your leading and title come closer.
ListTile(
leading : Icon(Icons.settings),
title : Text("Settings"),
minLeadingWidth : 10,
);
this code is the solution
...
contentPadding:EdgeInsets.all(0),
...