Flutter开发之——单组件布局容器-IntrinsicHeight和IntrinsicWidth

一 概述

  • IntrinsicHeight组件会根据子组件自身的高度扩展高度
  • IntrinsicWidth组件会根据子组件自身的宽度扩展宽度

二 IntrinsicHeight

2.1 构造方法

const IntrinsicHeight({ Key? key, Widget? child }) : super(key: key, child: child);

2.3 示例

2.3.1 未使用IntrinsicHeight

代码

body:Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            new Container(color: Colors.blue, width: 100.0),
            new Container(color: Colors.red, width: 50.0,height: 50.0,),
            new Container(color: Colors.yellow, width: 150.0),
          ],
        ),

效果图

2.3.2 使用IntrinsicHeight

代码

body:IntrinsicHeight(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            new Container(color: Colors.blue, width: 100.0),
            new Container(color: Colors.red, width: 50.0,height: 50.0,),
            new Container(color: Colors.yellow, width: 150.0),
          ],
        ),
      )

效果图

三 IntrinsicWidth

3.1 构造方法

const IntrinsicWidth({ Key? key, this.stepWidth, this.stepHeight, Widget? child })
    : assert(stepWidth == null || stepWidth >= 0.0),
      assert(stepHeight == null || stepHeight >= 0.0),
      super(key: key, child: child);

3.2 属性说明

属性说明取值
stepWidthdouble
stepHeightdouble
  • 当stepWidth不是null的时候,child的宽度将会是stepWidth的倍数,当stepWidth值比child最小宽度小的时候,这个值不起作用
  • 当stepWidth为null的时候,child的宽度是child的最小宽度
  • 当stepHeight不为null的时候,效果跟stepWidth相同
  • 当stepHeight为null的时候,高度取最大高度

3.3 示例

代码
IntrinsicWidth(
  stepHeight: 450.0,
  stepWidth: 300.0,
  child: Column(
    children: <Widget>[
      new Container(color: Colors.blue, height: 100.0),
      new Container(color: Colors.red, width: 150.0, height: 100.0),
      new Container(color: Colors.yellow,height: 150.0,),
    ],
  ),
)

效果图

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值