Make container widget fill parent vertically

前端 未结 6 935
天命终不由人
天命终不由人 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:14

    If you want a Container to fill all available space, you can simply use:

      width: double.infinity,
      height: double.infinity
    

    Explanation:

    While this might seem like a "hack", it's actually what the Flutter team uses as well. See, the most "proper" way is probably to use:

      constraints: BoxConstraints.expand(),
    

    But if you open up the source code of expand(), you will see:

      /// Creates box constraints that expand to fill another box constraints.
      ///
      /// If width or height is given, the constraints will require exactly the
      /// given value in the given dimension.
      const BoxConstraints.expand({
        double width,
        double height,
      }) : minWidth = width ?? double.infinity,
           maxWidth = width ?? double.infinity,
           minHeight = height ?? double.infinity,
           maxHeight = height ?? double.infinity;
    

    So if you are absolutely certain you want to fill all spaces, you can intuitively pass in a number bigger than the screen size, like double.infinity.

提交回复
热议问题