When you have a Flex widget, where the child with the maximum cross-axis size determines the cross-axis size of the rest.
If you try to use CrossAxisAlignment.stretch
with a Flex whose parent is unbounded along the cross-axis, you will get an error.
To solve this, you should use Intrinsic*
widgets. They do speculative pass on the Flex widget tree to determine the max size along the cross-axis and that becomes the constraint they pass to the Flex.
A Flex resolves its main axis size based on its children. It is able to do that by having children that are either sized or have non-zero flex factor. So it is unable to handle children like another Flex with the same direction, ScrollableView along the same axis, Container with no max value in the same axis, etc.
You need to wrap those in a widget with a flex factor like Expanded, Flexible or just give them a size with SizedBox.
When you have a Flexible or Expanded child in a Flex whose parent gives it unconstrained value for its main axis
When a Flex is inside a parent that is sends it unconstrained value for its main axis, the Flex tries to shrink wrap to its children. This cannot work with a child that tries to expand to as much space as possible. In this case one would think Flexible should work but it doesn't.
Say you have a Positioned widget that is unbounded along a particular axis. Let's say the width. If you need to put that in a Stack, you need to set the left
and right
of the widget. They act as margins in that sense.
If your stack does not have a non-positional widget and you decide to put positional widgets, the stack won't have a reference frame to work with. In which case it is going to throw an error.
Set the decoration of the TextField or TextFormField to the following:
decoration: const InputDecoration(isDense: true, contentPadding: EdgeInsets.zero)