[英]Leading Image overflows in ListTile
I have a ListView
with ListTile
.我有一个ListView
和ListTile
。 Each ListTile
has a title
with Text
, subtitle
with Text
, and leading
with an Image
.每个ListTile
都有一个带有Text
的title
、带有Text
leading
subtitle
和带有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.我不想给图像一个固定的大小,而是让它根据标题+副标题的固有高度调整到列表块的高度。
You should use CircleAvatar
as leading
in your ListTile
.您应该在ListTile
使用CircleAvatar
作为leading
。 It has a radius
property also that you can change, if you wish.如果您愿意,它也有一个radius
属性,您可以更改该属性。
leading: CircleAvatar(
backgroundImage: AssetImage("..."), // no matter how big it is, it won't overflow
),
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),
),
Do this:做这个:
leading: SizedBox(
height: 100.0,
width: 100.0, // fixed width and height
child: Image.asset(...)
)
My code and with a picture with subtitle and tile looks like below我的代码和带有副标题和平铺的图片如下所示
Widget _buildRow(WordPair pair) {
return ListTile(
title: Text(
'Title of messages comes here',
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
),
subtitle: Text(
pair.asPascalCase,
style: _font,
),
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 44,
minHeight: 44,
maxWidth: 44,
maxHeight: 44,
),
child: Image.asset('assets/message_lock.png', fit: BoxFit.cover),
),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.