In this article, I'm going to share an example on AnimatedPadding Widget.
Using AnimatedPadding Widget, you can animate the padding of the child widgets for the given duration.
![](https://fluttercentral.com/Uploads/0b67db27-acd5-412a-901b-a6ad1eb9ea0f.gif)
Thanks,
Here is how the final output is going to look.
![](https://fluttercentral.com/Uploads/0b67db27-acd5-412a-901b-a6ad1eb9ea0f.gif)
Here is the full code from main.dart file. You can simply copy-paste and run the code to see the output.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
double padValue = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("AnimatedPadding"),
),
body: Column(
children: <Widget>[
Expanded(
child: AnimatedPadding(
child: Container(
color: Colors.red,
),
duration: const Duration(seconds: 1),
padding: EdgeInsets.all(padValue),
curve: Curves.easeInOut,
),
),
Text('Padding Value: $padValue'),
ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('Add Padding'),
onPressed: () {
setState(() {
padValue = padValue + 10;
});
},
),
RaisedButton(
child: Text('Sub Padding'),
onPressed: () {
setState(() {
if(padValue != 0)
{
padValue = padValue - 10;
}
});
},
)
],
)
],
),
),
);
}
}
Srikanth