![]() |
VOOZH | about |
In Flutter, the AnimatedPhysicalModel widget is used to create animations that transition between different physical properties of a widget, such as elevation, shape, and colour. In this article, we are going to implement the AnimatedPhysicalModel widget. A sample video is given below to get an idea about what we are going to do in this article.
AnimatedPhysicalModel(
duration: Duration(milliseconds: 500), // Animation duration
curve: Curves.easeInOut, // Animation curve
elevation: _elevation, // Elevation (animate this property)
shape: BoxShape.rectangle, // Shape of the widget (rectangle or circle)
shadowColor: Colors.grey, // Color of the shadow
color: Colors.blue, // Background color of the widget
borderRadius: BorderRadius.circular(8.0), // Border radius
child: YourChildWidget(), // The widget you want to animate
)
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 AnimatedPhysicalModel widget that help to creating an animated card like container that changes its elevation, shape, and color when the "Add Elevation" or "Remove Elevation" button is pressed. Comments are added for better understanding.
AnimatedPhysicalModel(
duration: Duration(seconds: 1), // Animation duration
curve: Curves.easeInOut, // Animation curve
elevation: _isElevated ? 68.0 : 0.0, // Animate elevation
shape: BoxShape.rectangle, // Shape of the container
shadowColor: Colors.green, // Color of the shadow
color: Colors.green, // Color of the container
borderRadius: BorderRadius.circular(8.0), // Border radius
child: Container(
width: 200,
height: 200,
child: Center(
child: Text(
'Animated',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
),
),
Here is the full Code of main.dart file