I can create a ListTile from scratch by using a Row with 3 children inside. Let’s call these children leading, title and trailing. Then, I can set mainAxisSize to be of minimum size and done; you now have a ListTile that doesn’t grow as much as possible on the horizontal axis.
Consider the following example:
class ListTileShort extends StatelessWidget {
const ListTileShort({
super.key,
required this.title,
required this.leading,
required this.trailing,
});
final Widget title;
final Widget leading;
final Widget trailing;
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [leading, title, trailing],
);
}
}
As you can see, ListTileShort is attempting to behave like a built-in ListTile but shrinking as much as possible as a preference.
However, I don’t like the idea of simulating a ListTile with a Row. Therefore, I was wondering if it was possible to take the built-in ListTile and force it to shrink as much as possible on the horizontal axis?
2
Answers
One of the easiest way to remove all the spaces with
ListTile
is by usingdense
property like belowAnother way to do so is by using
visualDensity
propertyThere is property called
minLeadingWidth
as well. So, you can make it lessYou can wrap you
ListTile
byIntrinsicWidth
, this makes yourListTile
to be the minimum required to display its children:happy coding…