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)