[英]How to remove a card's inner padding in flutter?
I have placed a bookmark icon inside a card, but am unable to remove the inner padding of the card.我在卡片内放置了一个书签图标,但无法移除卡片的内部填充。 I would like to have the bookmark icon stick to the border of the card.
我想让书签图标粘在卡片的边框上。 How should I do it?
我该怎么做?
I have aligned the icon to "topRight", but it can't help.我已将图标与“topRight”对齐,但无济于事。
I just want to leave a full code removing the default margin to make it clear我只想留下一个完整的代码,删除默认边距以使其清楚
Card(
margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
elevation: 4,
child: Image.network(
model.item.image,
width: 20,
height: 200,
alignment: Alignment.center,
fit: BoxFit.cover,
),
您可以尝试将卡片的边距属性设置为EdgeInsets.zero
The Card widget has Padding by default. Card 小部件默认具有 Padding。 If this is not the desired behavior you could implement your own widget using Container that looks like a Card
如果这不是您想要的行为,您可以使用看起来像卡片的 Container 来实现您自己的小部件
You can wrap your Card
into a MediaQuery.removePadding
or MediaQuery.removeViewPadding
or MediaQuery.removeViewInsets
.您可以将
Card
包装到MediaQuery.removePadding
或MediaQuery.removeViewPadding
或MediaQuery.removeViewInsets
。 It works for all widgets with default padding/inner spacing and you can select the specific padding you want to remove ( top
, bottom
, right
or left
):它适用于所有具有默认填充/内部间距的小部件,您可以选择要删除的特定填充(
top
、 bottom
、 right
或left
):
MediaQuery.removeViewInsets(
removeRight: true,
removeLeft: true,
removeTop: true,
removeBottom: true,
context: context,
child: Card(...),
)
卡片的默认边距为 4,因此您必须将边距设置为零边距:EdgeInsets.zero,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.