I have a container that starts at zero height and needs to be expanded after a user interaction.
- I tried using AnimatedContainer / AnimatedSize and changing the child widget's height from
0
tonull
, but in both cases, Flutter complains that it cant' interpolate from0
tonull
. - I've also tried using BoxConstraints (with expanded using
maxHeight = double.infinity
) instead of explicit heights, in which case Flutter complains it can't interpolate from a finite value to an indefinite one. - I've also tried setting mainAxisSize to min/max, in which case Flutter complains that
vsync
isnull
.
How do I animate expanding a widget such that it dynamically grows big enough to wrap its contents? And if this can't be done dynamically, what's a safe way to size contents such that they make sense across screen sizes? In web dev, I know things like em
are sort of relative sizing, but in the context of Flutter, I don't see how to control the size of things reliably.
Update: As suggested by @pskink, wrapping the child in an Align widget and animating Align's heightFactor param accomplishes collapsing. However, I'm still having trouble getting collapse to work when the collapsing child itself has children. For example, Column widgets don't clip at all with ClipRect (see https://github.com/flutter/flutter/issues/29357), and even if I use Wrap instead of Column, that doesn't work if the Wrap's children are Rows. Not sure how to get clipping to work consistently.
expansion_tile.dart
source file - it usesAlign.heightFactor
that makes a trick – Cymbiform