How to use the constraints and sizes of other widgets during the build phase

后端 未结 2 572
离开以前
离开以前 2021-01-16 01:15

I want to make sure I cover all cases

  1. A Parent widget reads (and possibly uses) a child\'s size or constraints

  2. A Child widget reads (and po

2条回答
  •  梦谈多话
    2021-01-16 02:07

    Widgets can't do such thing on purpose. A Widget should never depend on the size and position or anything. Not even their children.

    If you ever face a situation where you need to, LayoutBuilder should be fine most of the time.

    If it's not, what you want to create isn't a Widget. But a RenderObject instead, one of the lower layer of flutter.

    Widgets such as Center, Stack or Column are in fact computed using RenderObject.

提交回复
热议问题