Skip to main content

How to Set Min Width and Min Height of a Container in Flutter

If you’re looking to create a specific size for your container in Flutter, you can use the minWidth and minHeight settings. This will constrain the size of the container to be at least as large as the values you specify.

Flutter has a convenient Container class that allows you to store, position and size any number of widgets on your screen. The basic idea behind it is like storing things in boxes!

The Container widget has BoxConstraints property that allows specifying the maximum and minimum width and height of the child widget inside it.

Here is an example showing how to set minWidth and minHeight for a Container:

Container(
  color: Colors.pink,
  constraints: BoxConstraints(
      minHeight: 100, minWidth: double.infinity),
  child: ListView(
    shrinkWrap: true,
    children: [
      ...List.generate(
        5,  
        (index) => Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            'Text: ${index}'
          ),
        ),
      ),
    ],
  ),
)

By continuing to use the site, you agree to the use of cookies.