flutter - correct way to create a box that starts at minHeight, grows to maxHeight

后端 未结 5 2021
时光说笑
时光说笑 2020-12-15 02:39

I have a container that I want to start off at a minimum size and grow (if its contents grow while user is adding content) to a maximum size, then stop.

The correct

5条回答
  •  天涯浪人
    2020-12-15 02:55

    There's no notion of "Starts from max/min size".

    The thing is, ContrainedBox only add constraints to it's child. But in the end, it doesn't pick a size.

    If you want your child to hit minSize, then they have to not expend. Which translate into not having a width/height of double.INFINITY. Fact is that double.INFINITY is the default value of many widgets, including Container.

    On the other hand, some widgets such as DecoratedBox have a default size of 0. Which means that this code :

    return new 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),
      ),
    );
    

    Will render a 5.0*5.0 red square.

提交回复
热议问题