I am trying to get a container to be exactly half the screen height[after considering the AppBar height] and half the screen width.
This is what I came up with...
<
If you want the container's height to be the half of the available space, you can use LayoutBuilder widget. With LayoutBuilder widget, you can know inside the builder function what the max available width and height would be. The example usage in your case would be like this:
Scaffold(
appBar: AppBar(),
body: Align(
alignment: Alignment.topCenter,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Container(
height: constraints.maxHeight / 2,
width: MediaQuery.of(context).size.width / 2,
color: Colors.red,
);
},
),
),
);