![]() |
VOOZH | about |
The AnimatedAlign widget in Flutter is used to create animated transitions for aligning a child widget within a parent container. It smoothly animates the alignment property, allowing you to move a child widget from one position to another with a specified duration.
In this article, we are going to implement the AnimatedAlign widget. A demo video is given below to get an idea of what we are going to do in this article.
To build this app, you need the following items installed on your machine:
Create a new Flutter application using the command Prompt. To create a new app, write the following command and run it.
flutter create app_nameTo know more about it refer this article: 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 setting the Theme of our App.
In this class, we are going to implement the AlignAnimation widget that helps to create animated transitions for aligning a child text widget within a parent container. In this class, we are going to align the container widget left to right and right to left.
AnimatedAlign(
duration: Duration(seconds: 1), // Animation duration
alignment: _isAlignedRight
? Alignment.centerRight
: Alignment.centerLeft, // Toggle alignment
child: Container(
width: 100,
height: 100,
color: Colors.green, // Background color of the container
child: Center(
child: Text(
'Hello',
style: TextStyle(color: Colors.white), // Text color
),
),
),
),
Code:
main.dart: