In this article, we will discuss flutter animated container in flutter in detail, how we can animated the animated container size, how can we implement animation in animated container. We will explain everything in detail of how the animation works in container, but first if you are new and want a complete setup and want to build your first app instantly, then click here, now let’s jump into flutter animated container.
Introduction: Flutter Animated Container
In our previous container customization article, we have understand how the container widget works, its color, height, width, decoration etc. In this article, we will discuss how the animated container works in flutter app. Its really a cool widget in which you can do animation directly by using its own properties. Let’s look at how to implement it in flutter app.
Implementation
AnimatedContainer( duration: Duration(milliseconds: 900))
Duration
duration: Duration(milliseconds: 900)
Decoration
AnimatedContainer( duration: Duration(milliseconds: 900), height: 300, width: 300, decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.circular(500)), )
Gesture Detector
double circular=0;
GestureDetector( onTap: () { setState(() { circular = 500; }); }, child: AnimatedContainer( duration: Duration(milliseconds: 900), height: 300, width: 300, decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.circular(circular)), ), )
Animated Size Of Container
double height = 50; double width = 50;
Let’s Animate The Container
GestureDetector( onTap: () { setState(() { height = 300; width = 300; }); }, child: AnimatedContainer( duration: Duration(milliseconds: 900), height: height, width: width, decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.circular(10)), ), )
Animated Container Position
Let’s now try to change the position of container using its animation. For that, we will use the margin property of container:
double bottom = 0;
We can see in the above video how beautifully the container position is changing. Let’s now try to build a beautiful animated containers animations. We will create this design that you can see below.
For this beautiful animated containers, we have used stack widget, column widget, container widget etc. to make the animation look more beautiful. You can now customize your container in your way like change the position, size, color and can even rotate the container using animation. We would love to see what you have made and would love to see your feedback on that animated container widget.
Conclusion
That’s all for this article, hope you enjoyed it and have learnt a lot from it. We would be looking forward for your response. Hope to see you in our next articles in which we will dig deep into other amazing Flutter concepts. Thank you reading this article.