如何计算孩子的大小 [英] How to calculate size of children

查看:82
本文介绍了如何计算孩子的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想实现可通过调整子项大小来调整自身大小的Widget,该怎么做?

If I want to implement Widget which sizes itself by sizing children, how do I do it?

不知何故,我需要推迟调整尺寸,直到所有孩子都知道尺寸为止.

Somehow I need to defer sizing until all children have figure out their size.

推荐答案

您可以使用CustomMultiChildLayoutCustomSingleChildLayout创建自定义布局.

You can create a custom layout, using CustomMultiChildLayout or CustomSingleChildLayout.

或者,如果这符合您的需求,请使用IntrinsicWidth/IntrinsicHeight小部件.

Or, if this fits your needs, use IntrinsicWidth/IntrinsicHeight widgets.

自定义布局基本上是仅具有定位子级的Stack.孩子们选择他们的尺寸,然后布局选择他们的位置. 但是它有一个局限性.布局尺寸不能取决于其子尺寸.

Custom layouts are basically a Stack with only positionned children. Children pick their size and then the layout choose their position. BUT it has a limitation. The layout size can't depend on it's children size.

Instrinsinc小部件更简单但也更受限制. 一个用例是将Row小部件包装在IntrincWidget中,以模拟css display: flex; align-items: stretch;

Instrinsinc widgets are much simpler but also more limited. A use case would be to wrap a Row widget in IntrincWidget, to simulate the css display: flex; align-items: stretch;

如果您需要更复杂的内容,则需要创建自己的RenderObject. 是的,这是违反直觉的.

If you need something more complex, you'll need to create your own RenderObject. Yup, this is counter-intuitive.

这篇关于如何计算孩子的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆