目录
ConstrainedBox、BoxConstraints案例
ConstrainedBox
先来看下 ConstrainedBox 属性
class ConstrainedBox extends SingleChildRenderObjectWidget {
//继承于 SingleChildRenderObjectWidget 说明只能有一个孩子
// constraints 为必须的
ConstrainedBox({
Key key,
@required this.constraints,
Widget child,
})
这里 constraints 为必传项 传入BoxConstraints实例,ConstrainedBox
可对子组件约束。如果你想让子组件的最小高度是80像素,你可以使用const BoxConstraints(minHeight: 80.0)
作为子组件的约束。
BoxConstraints
BoxConstraints用于设置 约束规则 如下
constraints: BoxConstraints(
minWidth: 230, //最小宽度
minHeight: 50.0 , //最小高度
maxWidth: 230, //最大宽度
maxHeight:180, //最大高度
),
BoxConstraints 还提供了比较编辑的一些构造如:
constraints: BoxConstraints.expand(width:250,height:250),