Animated Container with Animation

 import "package:flutter/material.dart";


void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});

@override
Widget build(BuildContext context)
{
return MaterialApp(
title: "Hello",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blueGrey,
),
home: const FlutterApp(),
);
}
}

class FlutterApp extends StatefulWidget
{
const FlutterApp({super.key});

@override
State<FlutterApp> createState()
{
return FlutterState();
}
}
class FlutterState extends State<FlutterApp>
{
var _width = 300.0;
var _height = 100.0;

bool flag = true;

//var bgColor = Colors.blueGrey;

Decoration myDecor = BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: Colors.blueGrey,
);

@override
Widget build(BuildContext context)
{
return Scaffold(
drawer: const Drawer(),
appBar: AppBar(
title: const Text("Animate Containers"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnimatedContainer(
width: _width,
height: _height,
decoration: myDecor,
//curve: Curves.slowMiddle,
//curve: Curves.fastOutSlowIn,
//curve: Curves.bounceOut,
curve: Curves.bounceInOut,
duration: const Duration(seconds: 2,),
child: const FlutterLogo(size: 75,),
),

const SizedBox(height: 50,),

ElevatedButton(
onPressed: (){

setState((){
if(flag){
_width = 100;
_height = 300;
flag = false;
myDecor = BoxDecoration(
borderRadius: BorderRadius.circular(21),
color: Colors.amber,
);
//bgColor = Colors.orange;

}else {
_width = 300;
_height = 100;
flag = true;
myDecor = BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: Colors.blueGrey,
);
//bgColor = Colors.blueGrey;
}
},);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text("Animate",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),
),
),
],
),
),
);
}
}

/*This is the another example of "AnimatedContainers"*/
/*class FlutterState extends State<FlutterApp>
{
bool _shape = true;

@override
Widget build(BuildContext context)
{
return Scaffold(
drawer: const Drawer(),
appBar: AppBar(
title: const Text("Flutter Animation"),
),
body: Center(
child: InkWell(
onTap: (){
setState((){
_shape = !_shape;
});
},
child: AnimatedContainer(
width: _shape ? 200 : 350,
height: _shape ? 500 : 150,
color: _shape ? Colors.amberAccent : Colors.black,
duration: const Duration(seconds: 1),
child: const FlutterLogo(size: 40,),
),
),
),
);
}
}*/

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter

Pagination First Practical in Flutter