我想我的图像大小相对于父Containerwidget
和定义的scale: 0.8,//here
在AssetImage()
,但它不工作?我如何解决这个问题?
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 50,
height: 50,
// color: Colors.green,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
image:
DecorationImage(
fit: BoxFit.fill,
image: AssetImage('images/prop/lock.png'),
scale: 0.8,//here
),
),
),
),
],
),
),
我认为LayoutBuilder()
不能正常工作。
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 50,
height: 50,
// color: Colors.green,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
child: LayoutBuilder(
builder: (context, constraints) {
return Image.asset(
'images/prop/lock.png',
fit: BoxFit.none,
height: constraints.maxHeight * 0.1,
width: constraints.maxWidth * 0.1,
);
},
),
),
),
],
),
),
3条答案
按热度按时间zazmityj1#
您可以像这样使用
LayoutBuilder
:gdrx4gfi2#
您可以将AspectRatio类用于该用途,如下所示
af7jpaap3#
必须将
fit
类型更改为BoxFit.none
,如下所示: