1

I have a container in which I have set the below constraints value

constraints: BoxConstraints(maxHeight: 300),

In the container widget, It has a child whose height is set to 200 but when the app is run the height is set to 300 instead of 200.

How to solve this?

bnayagrawal
  • 1,044
  • 3
  • 12
  • 22

1 Answers1

0

Found the answers here : https://stackoverflow.com/a/48676681/12838877

You have to set the minHeight or minWidth, to override the default value. just applied to my code and works as expected.

ConstrainedBox(
  constraints: new BoxConstraints(
    minHeight: 5.0,
    minWidth: 5.0,
    maxHeight: 30.0,
    maxWidth: 30.0,
  ),
  child: new DecoratedBox(
    decoration: new BoxDecoration(color: Colors.red),
  ),
)
pmatatias
  • 3,491
  • 3
  • 10
  • 30