我希望我的影像相對于父級調整大小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
),
),
),
),
],
),
),
uj5u.com熱心網友回復:
您可以將 AspectRatio 類用于該用途,如下所示
final double size = MediaQuery.of(context).size.aspectRatio;
uj5u.com熱心網友回復:
您必須將fit
type 更改為BoxFit.none
,如下所示:
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 100,
height: 100,
// color: Colors.green,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.none, // change this line
image: AssetImage('images/prop/lock.png'),
scale: 0.8,
),
),
),
),
],
),
)
uj5u.com熱心網友回復:
你可以LayoutBuilder
這樣使用:
Container(
margin: const EdgeInsets.only(top: 30),
alignment: Alignment.centerLeft,
child: Wrap(
children: [
GestureDetector(
onTap: () {
print("test");
},
child: Container(
width: 50,
height: 50,
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
child: LayoutBuilder(
builder: (context, constraints) {
return Image.asset(
'images/prop/lock.png',
fit: BoxFit.contain,
height: constraints.maxHeight * 0.3,
width: constraints.maxWidth * 0.3,
);
},
),
),
),
],
),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/533167.html
標籤:扑颤振布局
上一篇:這個copyWith模式是什么意思?<資料型別>函式()?<變數>
下一篇:如何制作這樣的彈出視窗