Is there a way to get the size of an existing widget?

I'm trying to get my user interface to display two buttons, one of which slightly overlaps the other, in the middle of a full-width map. Since the Stack will only be as wide as its non-positioned children, I added a non-positioned SizedBox child with a double.INIFINITY width to give myself a canvas to place the buttons, but I don't know what to put as the height of the SizedBox. Ideally, I want this widget to appropriately determine whether the user is on a phone or tablet, so I would rather base the height of the SizedBox around the current size of the buttons, rather than just hard-coded the number.

Is there a way to find the size of this existing widget? If not, what is the way to determine the height for objects that should look good on multiple screen sizes?

Code example:

new Card(
  child: new Stack(
    children: <Widget>[
      new SizedBox(
        width: double.INFINITY,
      ),
      new Positioned(
        left: 1.0,
        child: getButtonOne(),
      ),
      new Positioned(
        right: 1.0,
        child: getButtonTwo(),
      ),
    ],
  ),
),
+4
source share
1 answer

The short answer is no, because during the build function the widgets have not yet been laid out, so they have no size.

, , , . - , , .. , , .

+5

Source: https://habr.com/ru/post/1663573/


All Articles