use*_*643 16 flutter flutter-layout flutter-image
我有一个ListView带ListTile。每个ListTile都有一个titlewith Text、subtitlewithText和leadingwith Image。
现在,图像太大并且垂直延伸到下一行,与那里的图像重叠。
如何确保图像保持在边界内?
编辑:
我不想给图像一个固定的大小,而是让它调整到由标题+副标题的固有高度给出的列表图块的高度。
Cop*_*oad 41
您应该使用CircleAvatar为leading您的ListTile。radius如果您愿意,它还具有您可以更改的属性。
leading: CircleAvatar(
backgroundImage: AssetImage("..."), // no matter how big it is, it won't overflow
),
Run Code Online (Sandbox Code Playgroud)
如果你想使用矩形图像,你可以使用
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 44,
minHeight: 44,
maxWidth: 64,
maxHeight: 64,
),
child: Image.asset(profileImage, fit: BoxFit.cover),
),
Run Code Online (Sandbox Code Playgroud)
做这个:
leading: SizedBox(
height: 100.0,
width: 100.0, // fixed width and height
child: Image.asset(...)
)
Run Code Online (Sandbox Code Playgroud)