Flutter 溢出布局 OverflowBox

import 'package:flutter/material.dart';

void main() => runApp(new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text("overflowBox demo"),
        ),
        body: new Container(  //1 注意:父容器的宽高是200 减去pading后是180
          padding: EdgeInsets.all(10),
          color: Colors.green,
          width: 200,
          height: 200,
          child: new OverflowBox(
            maxHeight: 400,//2 不能小于父容器的高度180
            child: new Container(
              color: Colors.deepOrange,
              width: 200,
              height:600,
            ),
          ),
        ),
      ),
    ));

 

设置 了 maxheight ,maxwidth 子控件不会超出设置的范围;

设置了 minheight,minwidth ,子控件不会小于设置的范围;

注意:

设置 maxheight,和maxwidth的时候 它们的值不能小于父控件的宽高,如果有pading可以限定到 父控件的宽高减去pading的值。

如: 当前例子中  注释1 :父容器的宽高是200 减去pading后是180,那么 OverflowBox的值maxheight,maxwidth,就不能小于这个值180。否则会报错:

I/flutter (22732): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (22732): The following assertion was thrown during performLayout():
I/flutter (22732): BoxConstraints has non-normalized height constraints.
I/flutter (22732): These invalid constraints were provided to RenderConstrainedBox's layout() function by the following
I/flutter (22732): function, which probably computed the invalid constraints in question:

 

错误信息:很明确

I/flutter (22732): The offending constraints were:
I/flutter (22732):   BoxConstraints(180.0<=w<=290.0(maxwidth), 180.0<=h<=170.0(maxheight); NOT NORMALIZED) 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值