美文网首页
Flutter--AspectRatio组件

Flutter--AspectRatio组件

作者: 小迷糊_dcee | 来源:发表于2020-12-03 23:19 被阅读0次

一、介绍

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,
       ),
     ),
   );
企业微信截图_16070086728073.png
return Container(
     height: 100,//父组件设置高度
     child: AspectRatio(
       aspectRatio: 2,
       child: Container(
         color: Colors.red,
       ),
     ),
   );
企业微信截图_16070086864716.png

相关文章

网友评论

      本文标题:Flutter--AspectRatio组件

      本文链接:https://www.haomeiwen.com/subject/hzavwktx.html