Make container widget fill parent vertically

前端 未结 6 994
天命终不由人
天命终不由人 2020-12-25 09:38

TL;DR Need the container to fill the vertical space so that it can act as a ontap listener. Have tried most solutions but nothing seems to work.

So what I am trying

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-25 10:17

    I propose using Expanded widget (which allows us to avoid IntrinsicHeight widget), combine it with the Container's alignment property and therefore make it work properly even if the Container is not the only one at the screen.

    Expanded(
      child: Container(
        alignment: Alignment.center,
        child: Text('Your text', textAlign: TextAlign.center))),
    

    That way one also avoids potential app's crash which occurs often when you accidentally expand to infinity some parts of the widget tree both horizontally and vertically (that is why you are not able to use BoxConstraints widget in many cases).

    One can read more about the problems of passing constraints in Flutter here - a must read: https://medium.com/flutter-community/flutter-the-advanced-layout-rule-even-beginners-must-know-edc9516d1a2

提交回复
热议问题