AnimatedPadding Example in Flutter

This Article is posted by seven.srikanth at 8/22/2019 3:56:17 AM




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.

Here is how the final output is going to look.



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;
}
});
},
)
],
)

],
),
),
);
}
}


Thanks,
Srikanth



Tags: AnimatedPadding; Animation in Flutter;








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com