Sizing a container to exact half the screen size in flutter

后端 未结 5 1610
天命终不由人
天命终不由人 2021-02-18 23:51

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...

<
5条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 00:25

    The best way and simplest route to this and similar problems is simply by using FractionallySizedBox widget ; e.g

    FractionallySizedBox(
        alignment: Alignment.topCenter,
        widthFactor: 0.5,
        child: Container(
        height: 100,
      ),
    ),
    

    This widget (FractionallySizedBox) lets you build up your child by specifying the fraction of the parent width (or height) which is available to the child widget. After that , by specifying the alignment , 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.

提交回复
热议问题