0

How to make animation with screen width and height? I have this code in initState but I can't get height of the screen before initState. How to deal with this?

controller = AnimationController(
        vsync: this,
        duration: Duration(milliseconds: 1500),
      );

Tween<double> _height = Tween(begin: 0.0, end: screenHeight);

      animationHeight = _height.animate(controller)..addListener(() {
        setState(() {});
      })
        ..addStatusListener((status) {
          if (status == AnimationStatus.completed) {

            //controller.reset();
          }
          if(status == AnimationStatus.reverse){
            setState(() {
            });
          }
        });
Filip
  • 2,191
  • 3
  • 12
  • 25
  • Maybe if you pass a very big number as screenHeight? For example `screenHeight = double.infinity` – John Arnok Jul 03 '20 at 20:03
  • @JohnArnok I need exact height of screen :/ – Filip Jul 03 '20 at 20:46
  • 1
    Inside `initState` use [addPostFrameCallback](https://stackoverflow.com/a/50682918/13625305) and [MediaQuery.of(context).size.height](https://stackoverflow.com/a/52319524/13625305) to find the device height. – dev-aentgs Jul 04 '20 at 11:11

0 Answers0