flutter - 在 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,
);
解决方案
将 的值更改为fit
类似BoxFit.scaleDown
或BoxFit.contain
以获得所需的结果。请参阅BoxFit 文档以了解这些值的含义。
推荐阅读
- javascript - 将二维数组转换为多行对象
- php - 重写规则在测试器中有效,但在 .htaccess 中无效
- c++ - SFML: 错误: ')' 标记之前的预期主表达式
- azure-data-catalog - 我们可以重命名标签吗?
- php - 如何使用 PHP 在 AD 安全组中搜索成员
- javascript - 嵌套数组中的 JavaScript 循环(新手)
- java - IntelliJ IDE 中带有 Gauge 的 Maven 缺少文件夹
- c# - 无法对从 MessageResource.CreateAsync 返回的 Twilio MessageResource 对象进行 Json 序列化
- mysql - 有没有办法在不使用括号中的条件的情况下编写此查询?
- scala - scala:使用不需要类型的类型参数的类方法