How to animate a widget when it becomes visible in flutter?

Posted by Jennifer | Updated on

How to animate a widget when it becomes visible in flutter?

1. Create a GlobalKey and an AnimationController for each of your widgets.

2. Use a ScrollController to listen for scroll events in your scroll view (doesn’t have to be a ListView)

3. Use GlobalKey.currentContext.findRenderObject() to get the reference to the actual object that is rendered on screen.

4. If the RenderObject exists, get its relative position (getTransformTo) and check if the position is visible in the scroll view

5. Start the animation. To make sure that it is only triggered once, check the AnimationStatus of the AnimationController.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers