'MediaQuery.of() Flutter

i am searching a way for sizing a element in flutter with the dimensions of the parent widget. How can I do?

I tried with MediaQuery.of(WidgetParent) but this not work.

Thanks



Solution 1:[1]

If you want to size the current widget with respect to the parent widget's dimensions, check this Widget FractionallySizedBox

Solution 2:[2]

The MediaQuery.of(context) returns the device's screen size, not the parent widget.

You can get the size of the parent widget by using the LayoutBuilder.
YOUTUBE: LayoutBuilder (Flutter Widget of the Week)

LayoutBuilder(
  builder: (context, constraints) {
    constraints.maxWidth;

    ...
  }
);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pathik Patel
Solution 2 MaNDOOoo