一、介绍
AspectRatio组件,设置子组件的宽高比
二、源码
const AspectRatio({
Key key,
@required this.aspectRatio,//宽高比
Widget child,//子组件
}) : assert(aspectRatio != null),
assert(aspectRatio > 0.0),
// can't test isFinite because that's not a constant expression
super(key: key, child: child);
三、属性介绍
属性 | 说明 |
---|---|
aspectRatio | 宽高比 子组件的高是根据父组件的宽计算的 父组件的宽高设置具体的值,aspectRatio的值无效 |
child | 子组件 |
四、demo
return Container(
width: 100,//父组件设置宽度
child: AspectRatio(
aspectRatio: 0.5,
child: Container(
color: Colors.red,
),
),
);

return Container(
height: 100,//父组件设置高度
child: AspectRatio(
aspectRatio: 2,
child: Container(
color: Colors.red,
),
),
);

网友评论