About Your code snippet
return LayoutBuilder(
builder:
(BuildContext context, BoxConstraints constraints) {
print(constraints.maxHeight);
return Container( // how to get height of the container
child: Text('hello,\nhow to get\nheight of the parent layout'),
);
},
);
You are trying to get child size. To get parent size, you need to use LayoutBuidler
as child on that widget.
like this,
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(body: LayoutBuilder(
builder: (context, bodyConstraints) {
print("body height : ${bodyConstraints.maxHeight}");
return Container(
height: 200,
color: Colors.deepOrangeAccent,
child: LayoutBuilder(
builder: (context, containerConstraints) {
print("Container height ${containerConstraints.maxHeight}");
return Text(
" body Height: ${bodyConstraints.maxHeight} \n container height: ${containerConstraints.maxHeight}",
);
},
),
);
},
));
}
}
does it solve your issue?