https://www.youtube.com/@truecoders?s...
@TrueCoders
AnimatedContainer: The AnimatedContainer widget animates changes to its properties, such as its size, color, and padding.
The AnimatedContainer is a built-in Flutter widget that animates changes to its properties, such as size, color, padding, border, and decoration. The widget is similar to the Container widget, but it adds animation capabilities to its properties.
When a property of the AnimatedContainer changes, the widget automatically animates the transition between the old and new values. For example, if the size of the AnimatedContainer changes from small to large, the widget smoothly animates the size change rather than abruptly changing the size.
The AnimatedContainer widget takes a duration parameter that specifies the duration of the animation. Developers can also specify the animation curve to use for the transition. The widget automatically animates changes to its properties using the provided duration and curve.
Here's an example of using the AnimatedContainer widget:
AnimatedContainer(
duration: Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
height: _isExpanded ? 200.0 : 100.0,
width: _isExpanded ? 200.0 : 100.0,
color: _isExpanded ? Colors.red : Colors.blue,
child: Center(
child: Text('Click me'),
),
)
In this example, the AnimatedContainer changes its height, width, and color properties based on the value of `_isExpanded`. When `_isExpanded` is true, the AnimatedContainer expands to a height and width of 200.0 and changes color to red. When `_isExpanded` is false, the AnimatedContainer contracts to a height and width of 100.0 and changes color to blue. The animation uses a duration of 1 second and the `fastOutSlowIn` curve for a smooth and natural transition.