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