I want create statefulWidget
and want in this widget get parent widget height. Don't want do this by sending height data from parent widget. How can I do this?
Get parent widget height in flutter
Asked Answered
Use LayoutBuilder as a child widget.
LayoutBuilder(builder: (ctx, constraints) {
return
Container(
height: constraints.maxHeight * 0.5,
width: constraints.maxWidth * 0.5,
child: Text('Inside Layout Builder'),
);
})
As per this code Container
will use half of the height and width of parent widget.
© 2022 - 2024 — McMap. All rights reserved.
LayoutBuilder
? the docs say: "Builds a widget tree that can depend on the parent widget's size." – KilburnLayoutBuilder
? – ChrysalisFractionallySizedBox
- docs say: "A widget that sizes its child to a fraction of the total available space." - that way you can do that with oneWidget
while usingLayoutBuilder
you need most likely twoWidget
s:LayoutBuilder
and someSizedBox
orContainer
– Kilburn