xster
xster

Reputation: 6677

Can a ConstrainedBox lazily refer to to the size of another widget?

Sort of like how flex in Flexible refers to the size of its parent, can a ConstrainedBox constrain size to a fraction of another widget's size instead of absolute values?

Example

new SizedBox( size: ... child: new Stack( child: new Align( alignment: ... child: ConstrainedBox( constraints: new BoxConstraints.relativeToParent(maxHeightRatio: 0.3), child: ... ), ), ), ),

Upvotes: 1

Views: 313

Answers (1)

Collin Jackson
Collin Jackson

Reputation: 116818

You can use the widthFactor and heightFactor arguments to Align to size your child. If your logic is more complicated, you can use a LayoutBuilder to get the size of the parent widget and use that to build your BoxConstraints.

Upvotes: 1

Related Questions