颤动-创建以minHeight开始,增长到maxHeight的框的正确方法
问题内容:
我有一个容器,我希望以最小尺寸开始,然后增长(如果用户添加内容时其内容增长)到最大尺寸,然后停止。
正确的小部件似乎是ConstrainedBox,如下所示:
new ConstrainedBox(
constraints: new BoxConstraints(
minHeight: 35.0,
maxHeight: 60.0,
),
child: ...child with growing content (has default height 25.0)...
),
但是,这将以maxHeight开头。
我尝试使用hasBoundedHeight,但似乎无法为其构造正确的语法或在文档中找到示例。
使包装盒按所述方式工作的最佳方法是什么?
问题答案:
没有“从最大/最小大小开始”的概念。
事实是,ContrainedBox
仅对其子项添加约束。但是最后,它没有选择大小。
如果您希望孩子达到minSize,则 不必 花费。其转化为 不
具有的宽度/高度double.INFINITY
。事实是,这double.INFINITY
是许多小部件(包括)的默认值Container
。
另一方面,某些小部件(例如)DecoratedBox
的默认大小为0。这意味着该代码:
return new ConstrainedBox(
constraints: new BoxConstraints(
minHeight: 5.0,
minWidth: 5.0,
maxHeight: 30.0,
maxWidth: 30.0,
),
child: new DecoratedBox(
decoration: new BoxDecoration(color: Colors.red),
),
);
将呈现一个5.0 * 5.0的红色正方形。