Flutter - Animate Image Rotation
Last Updated :
08 Jun, 2025
In Flutter, Image.assets() or Image.network() Widget is used to display images from locally or from a URL. Images can be locally stored in the program or fetched from a network and can be displayed using the Image Widget. Animations can be applied to Images via many techniques. Hence, in this article, we are going to apply animation to the Image Rotation, which will give a smooth rotation of the image.
A sample video is provided below to give you an idea of what we will cover in this article.
Demo Video
Step-by-Step Implementation
Step 1: Create a new Flutter Application
Create a new Flutter application using the command Prompt. To create a new app, write the following command and run it.
flutter create app_name
To know more about it refer this article: 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 setting the Theme of our App.
Dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green, // Set the app's primary theme color
),
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
Step 5: Create MyHomePage Class
In this class, the initState method initializes the animation controller and defines an animation using a Tween. The Tween specifies the starting and ending values for the rotation angle. The Transform.rotate widget is used to rotate the image based on the current value of the animation. Basically, in this class, we are going to implement the main logic for applying animation to the rotation of the image. Comments are added for better understanding.
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
// Use Transform.rotate to rotate the
// Image based on the animation value
return Transform.rotate(
angle: _animation.value,
child: Image.network(
'https://static.startuptalky.com/2021/06/GeeksforGeeks-StartupTalky.jpg', // Replace with your image
width: 200,
height: 200,
),
);
},
),
Dart
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _animation;
@override
void initState() {
super.initState();
// Create an animation controller
_controller = AnimationController(
vsync: this, // vsync is set to this for performance reasons
duration: Duration(seconds: 2), // Set the duration of the animation
);
// Create a Tween for the rotation angle
_animation = Tween<double>(
begin: 0, // Start rotation angle
end: 2 * 3.141, // End rotation angle (2 * pi for a full circle)
).animate(_controller);
// Repeat the animation indefinitely
_controller.repeat();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Rotation Animation'),
backgroundColor: Colors.green,
foregroundColor: Colors.white,
),
body: Center(
child: AnimatedBuilder(
animation: _animation,
builder: (context, child) {
// Use Transform.rotate to rotate the Image based on the animation value
return Transform.rotate(
angle: _animation.value,
child: Image.network(
'https://static.startuptalky.com/2021/06/GeeksforGeeks-StartupTalky.jpg', // Replace with your image asset
width: 200,
height: 200,
),
);
},
),
),
);
}
@override
void dispose() {
// Dispose of the animation controller when the widget is disposed
_controller.dispose();
super.dispose();
}
}
Complete Source Code
main.dart:
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green, // Set the app's primary theme color
),
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _animation;
@override
void initState() {
super.initState();
// Create an animation controller
_controller = AnimationController(
vsync: this, // vsync is set to this for performance reasons
duration: Duration(seconds: 2), // Set the duration of the animation
);
// Create a Tween for the rotation angle
_animation = Tween<double>(
begin: 0, // Start rotation angle
end: 2 * 3.141, // End rotation angle (2 * pi for a full circle)
).animate(_controller);
// Repeat the animation indefinitely
_controller.repeat();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Rotation Animation'),
backgroundColor: Colors.green,
foregroundColor: Colors.white,
),
body: Center(
child: AnimatedBuilder(
animation: _animation,
builder: (context, child) {
// Use Transform.rotate to rotate the Image based on the animation value
return Transform.rotate(
angle: _animation.value,
child: Image.network(
'https://static.startuptalky.com/2021/06/GeeksforGeeks-StartupTalky.jpg', // Replace with your image asset
width: 200,
height: 200,
),
);
},
),
),
);
}
@override
void dispose() {
// Dispose of the animation controller when the widget is disposed
_controller.dispose();
super.dispose();
}
}
Output:
Similar Reads
Flutter - Animated Navigation By default, Flutter has no animation when navigating from one Screen to another Screen. But in this tutorial, we are going to learn how to animate the Screen Transition. Project Setup Before directly applying to your existing project, practice the code in some example projects. For this tutorial, we
4 min read
Flutter - Page Transition Animation In Flutter, we can easily animate or handle the page transitions by using the page_transition package. The page_transition package is a valuable addition to the Flutter package, offering a variety of transition effects that can elevate the app's UI. In this article, we are going to explore how to in
6 min read
Flutter - Animation in Route Transition Routes are simply Pages in Flutter applications. An application often needs to move from one page to another. However, animations can be used to make these transitions smoother. These animations can be used to curve or tween the Animation object of the PageRouteBuilder class to alter the transition
3 min read
Animated Text in Flutter Animations make the UI more interactive and enhance the user experience. There is no limitation of creativity when it comes to animations or making the application more interactive. In Flutter, we got an easy way to display Animated text. In this article, we will see how we can animate texts using a
3 min read
Flutter - Animation Text Fade Transition A fade text effect typically refers to a visual effect in which text gradually appears or disappears by changing its opacity over time, creating a smooth transition between visible and invisible states. In this article we are going to create a Text then we are going to add a Fading effect on it over
4 min read