Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get parent widget height in flutter

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?

like image 794
esfsef Avatar asked Apr 25 '26 06:04

esfsef


1 Answers

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.

like image 117
Alpesh Rathod Avatar answered Apr 26 '26 20:04

Alpesh Rathod