1

I want to animate the height property of the container (AnimatedContainer in code below), but I don't want to set hard numbers like this (height: _visible2 ? 160 : 40.9) because height of this container is otherwise relative to its children content (mainly Text)

AnimatedContainer(
  curve: Curves.ease,
  height: _visible2 ? 160 : 40.9,
  duration: Duration(milliseconds: 350),
  child: AnimatedOpacity(
    duration: Duration(milliseconds: 400),
    opacity: _visible2 ? 1.0 : 0,
    child: GestureDetector(
      onTap: () {
        _visible2 
          ? setState(() {
            _visible2 = !_visible2;
          })
          : null;
      },
      child: myWidget
    ),
  ),
)

Is there a way to animate from zero to relative height (for example height of this container can change in landscape mode due to more room for text to lay itself on the screen) ?

Ken White
  • 123,280
  • 14
  • 225
  • 444
Valeriy
  • 11
  • 2
  • have you tried not setting a height for the container cause by default the container will have a height relative to its child – CoderUni Jun 20 '20 at 03:20
  • Yes, problem is solely with animating it, because if I don't set hard numbers - animation simply will not work. – Valeriy Jun 20 '20 at 10:51
  • 1
    You can also use other widgets or build one your own. Check these out: https://flutter.dev/docs/development/ui/animations/tutorial and https://www.youtube.com/watch?v=l9uHB8VXZOg – CoderUni Jun 20 '20 at 11:48

0 Answers0