![]() |
VOOZH | about |
The AnimatedBuilder widget in Flutter is a powerful utility widget that is used for creating complex animations by rebuilding a part of the widget tree in response to changes in an animation's value. It is especially useful when you want to animate properties of child widgets that cannot be directly animated using widgets like AnimatedContainer or AnimatedOpacity.In this article, we are going to implement the AnimatedBuilder widget. A sample video is given below to get an idea about what we are going to do in this article.
To build this app, you need the following items installed on your machine:
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
First of all import material.dart file.
import 'package:flutter/material.dart';
Here the execution of our app starts.
In this class we are going to implement the MaterialApp , here we are also set the Theme of our App.
In this class we are going to Implement the AnimatedBuilder widget that help to create a transition of a container of width and height of 50.0 to 200.0. Comments are added for better understanding.
AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, Widget? child) {
return Container(
width: _animation.value, // Animate the width
height: _animation.value, // Animate the height
color: Colors.green, // Container background color
child: Center(
child: Text(
'Hello',
style: TextStyle(color: Colors.white), // Text color
),
),
);
},
),
Here is the full Code of main.dart file