Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leading Image overflows in ListTile

I have a ListView with ListTile. Each ListTile has a title with Text, subtitle with Text, and leading with an Image.

Now, the Image is too big and vertically stretches into the next row, overlapping the Image there.

How can I make sure that the Image stays within the bounds?

EDIT:

I’d like not to give the image a fixed size, but rather let it adjust to the height of the list tile as given by title+subtitle’s intrinsic height.

like image 364
user3612643 Avatar asked Apr 11 '19 22:04

user3612643


People also ask

How do you increase the height of a ListTile?

A ListTile is a very, very basic built-in widget that can only be a particular height, and there is nothing you can do about it. If you want to do anything visually cool, with pictures etc like I have shown in my question, you have to create a custom CARD instead.


1 Answers

enter image description here

You should use CircleAvatar as leading in your ListTile. It has a radius property also that you can change, if you wish.

leading: CircleAvatar(
  backgroundImage: AssetImage("..."), // no matter how big it is, it won't overflow
),

enter image description here

If you wanna use rectangle image, you an use

leading: ConstrainedBox(
  constraints: BoxConstraints(
    minWidth: 44,
    minHeight: 44,
    maxWidth: 64,
    maxHeight: 64,
  ),
  child: Image.asset(profileImage, fit: BoxFit.cover),
),
like image 136
CopsOnRoad Avatar answered Nov 17 '22 23:11

CopsOnRoad