gpt4 book ai didi

flutter - LayoutBuilder : constrains. maxHeight 返回无穷大

转载 作者:行者123 更新时间:2023-12-03 03:09:42 24 4
gpt4 key购买 nike

我正在尝试获取constrains.maxHeight。

这是我使用的代码:

LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
print(constraints.maxHeight);
return Column(
children: <Widget>[
LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
print(constraints.maxHeight);
return Text(constraints.maxHeight.toString());
}),
],
);
}),

第一个给出:812,但第二个 LayoutBuilder 给出无穷大。
(我的Code简化了,我也用了专栏里的其他东西,但是tot test,我只把LayoutBuilder放在里面了。)

我究竟做错了什么?

谢谢!

最佳答案

对于放置在 Column 中的元素,约束是无穷大或无界的。 .包裹 LayoutBuilderExpanded小部件并尝试。

In Flutter, widgets are rendered by their underlying RenderBox objects. Render boxes are given constraints by their parent, and size themselves within those constraints. Constraints consist of minimum and maximum widths and heights; sizes consist of a specific width and height.

Generally, there are three kinds of boxes, in terms of how they handle their constraints:

Those that try to be as big as possible. For example, the boxes used by Center and ListView. Those that try to be the same size as their children. For example, the boxes used by Transform and Opacity. Those that try to be a particular size. For example, the boxes used by Image and Text. Some widgets, for example Container, vary from type to type based on their constructor arguments. In the case of Container, it defaults to trying to be as big as possible, but if you give it a width, for instance, it tries to honor that and be that particular size.

Others, for example Row and Column (flex boxes) vary based on the constraints they are given, as described below in the “Flex” section.



documentation

关于flutter - LayoutBuilder : constrains. maxHeight 返回无穷大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59509620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com