Auto expanding Container in flutter -- for all devices

Have you tried not specifying height at all? The Container should wrap according to the child in this case.

Otherwise, the widget has a child but no height, no width, no constraints, and no alignment, and the Container passes the constraints from the parent to the child and sizes itself to match the child.

Above is an extract from the official flutter documentation for Container.

Here is the official flutter documentation link.


You can use FittedBox, this will resize your text according to available area.

You can use it like this :

FittedBox(child: Text('...............Your text...............'));

I would suggest you to use Constraints...this will set Container height according to the Text child's requirement. Please see the example...

Container(
    constraints: BoxConstraints(
    maxHeight: double.infinity,
),
child: Column(
children: [
  Text(
    'Hello flutter...i like flutter...i like google...',
    softWrap: true,
    style: TextStyle(
        color: Colors.white, fontSize: 20 , ),

  ),],),)