一、介紹
AspectRatio組件钥庇,設(shè)置子組件的寬高比
二牍鞠、源碼
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 | 寬高比 子組件的高是根據(jù)父組件的寬計算的 父組件的寬高設(shè)置具體的值评姨,aspectRatio的值無效 |
child | 子組件 |
四难述、demo
return Container(
width: 100,//父組件設(shè)置寬度
child: AspectRatio(
aspectRatio: 0.5,
child: Container(
color: Colors.red,
),
),
);
企業(yè)微信截圖_16070086728073.png
return Container(
height: 100,//父組件設(shè)置高度
child: AspectRatio(
aspectRatio: 2,
child: Container(
color: Colors.red,
),
),
);
企業(yè)微信截圖_16070086864716.png