【布局 widget】OverflowBox 与 SizedOverflowBox

OverflowBox

对于 OverflowBox ,文档只有一句话:把不同的约束强加给 child,允许 child overflow 父容器。这句话说的太简略了,使用的时候还是一头雾水,代码逻辑是这样的:

 BoxConstraints _getInnerConstraints(BoxConstraints constraints) {return BoxConstraints(minWidth: _minWidth ?? constraints.minWidth,maxWidth: _maxWidth ?? constraints.maxWidth,minHeight: _minHeight ?? constraints.minHeight,maxHeight: _maxHeight ?? constraints.maxHeight,);}@overridevoid performLayout() {if (child != null) {child?.layout(_getInnerConstraints(constraints), parentUsesSize: true);alignChild();}} 

用语言描述就是,优先取 OverflowBox 的 minWidth,maxWidth,minHeight,maxHeight,父级的约束值是用来兜底的,这样就清晰多了。parentUsesSize: true 是因为 OverflowBox 有 align 属性,需要摆放 child,比如想把 child 右对齐,如果不知道 child 的 size ,就无法知道 child 左边的 offset 是多少,所以 child 尺寸变化的时候,需要通知 OverflowBox ,让 OverflowBox 重新计算 offset ,调

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值