Flutter - Animated AlertDialog in Flutter
Last Updated :
24 Apr, 2025
Animating an AlertDialog in Flutter involves using the Flutter animations framework to create custom animations for showing and hiding the dialogue. In this article, we are going to add an animation to an AlertDialog. A sample video is given below to get an idea about what we are going to do in this article.
Basic Syntax of Creating an Animation in Flutter
Create an AnimationController:
final AnimationController _controller = AnimationController(
duration: Duration(seconds: 1), // Set the duration of the animation
vsync: this, // Provide a TickerProvider, often you can use 'this'
);
Define the Animation:
final Animation<double> _animation = Tween<double>(
begin: 0.0, // Starting value of the animation
end: 1.0, // Ending value of the animation
).animate(_controller);
Step By Step Implementation
Step 1: Create a New Project in Android Studio
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.
Step 2: Import the Package
First of all import material.dart file.
import 'package:flutter/material.dart';
Step 3: Execute the main Method
Here the execution of our app starts.
Dart
void main() {
runApp(MyApp());
}
Step 4: Create MyApp Class
In this class we are going to implement the MaterialApp , here we are also set the Theme of our App.
Dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Define the app's theme
theme: ThemeData(
// Set the app's primary theme color
primarySwatch: Colors.green,
),
debugShowCheckedModeBanner: false,
home: OpenDialog(),
);
}
}