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...
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Flexible(
child: Container(
width: MediaQuery.of(context).size.width / 2,
color: Colors.red,
),
),
Flexible(
flex: 1,
child: Container(),
)
],
),
);
}
}
The best way and simplest route to this and similar problems is simply by using
FractionallySizedBox
widget ; e.gThis widget (
FractionallySizedBox
) lets you build up yourchild
by specifying the fraction of the parent width (or height) which is available to thechild
widget. After that , by specifying thealignment
, you can specify the manner the rest of the space would be allocated.For more help on this widget , please visit the offical help page of this widget.