【发布时间】:2020-01-18 13:01:16
【问题描述】:
为什么Image widget不能在指定宽高的Container中设置特殊的宽高?
class HomeContent extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return Center(
child: Container(
child: Image.network(
"http://a1.att.hudong.com/60/38/01200000194369136323385641912.jpg",
width: 20,
height: 20,
),
width: 400,
height: 400,
decoration: BoxDecoration(
color: Colors.yellow,
),
),
);
}
}
结果是这样的,你看到Container中的Image占据了400.0的宽度,而不是20。
EDIT-01
我尝试使用MediaQuery设置Image的宽高,但没有效果。
class HomeContent extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return Center(
child: Container(
child: Image.network(
"http://a1.att.hudong.com/60/38/01200000194369136323385641912.jpg",
width: MediaQuery.of(context).size.height/2,
height: MediaQuery.of(context).size.height/2,
),
width: 400,
height: 400,
decoration: BoxDecoration(
color: Colors.yellow,
),
),
);
}
}
【问题讨论】:
标签: flutter