4. Fade the box in and out

You have a green box on screen and a button to toggle the visibility
to true or false. How to fade the box in and out? With an
AnimatedOpacity widget.

The AnimatedOpacity widget requires three arguments:

opacity: A value from 0.0 (invisible) to 1.0 (fully visible).

duration: How long the animation should take to complete.

child: The widget to animate. In this case, the green box.

Interactive example

Animate the properties of a container

Add a drawer to a screen