我正在尝试创建一张以图像为背景的卡片。问题是,图像溢出卡片,所以不显示角落。
我需要将图像设置为卡片的背景或将卡片溢出行为设置为不溢出。但我找不到任何属性。
这是我的名片:
Widget _buildProgrammCard() {
return Container(
height: 250,
child: Card(
child: Image.asset(
'assets/push.jpg',
fit: BoxFit.cover,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
),
);
它看起来像这样:
最佳答案
Other Way without using - ClipRRect
Widget - 是设置 semanticContainer: true,
of Card
Widget。
示例代码如下:
Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Image.network(
'https://placeimg.com/640/480/any',
fit: BoxFit.fill,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
),
输出:
关于dart - Flutter 如何用背景图片创建卡片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53866481/