首页 > 解决方案 > 在 ListTile 的前导中使用时不适合图像

问题描述

资产图像为 200x200 像素,但是当它用于 ListTile 的前导时,它并没有像预期的那样安装。渲染的图像看起来是这样的。如何按照图像高度和宽度属性中定义的比例按 90x90 显示它?

在此处输入图像描述

Card(
  key: ValueKey(favorites[index]),
  margin: EdgeInsets.all(20),
  child: ListTile(
    leading: kNoImage,
    title: Text(favorites[index]),
    subtitle: Text(favorites[index]),
    trailing: IconButton(
      icon: Icon(Icons.close),
      onPressed: () {
        debugPrint('entry deleted');
      },
    ),
  ),
);

const kNoImage = Image(
  image: AssetImage('assets/no-user-image.png'),
  height: 90,
  width: 90,
  fit: BoxFit.cover,
);

标签: flutter

解决方案


将 的值更改为fit类似BoxFit.scaleDownBoxFit.contain以获得所需的结果。请参阅BoxFit 文档以了解这些值的含义。


推荐阅读