import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
AnimationController animationController;
Animation animation;
Animation animationColor;
CurvedAnimation curve;
@override
void initState() {
// TODO: implement initState
animationController = AnimationController(
vsync: this,
//value: 32.0,
//lowerBound: 0.0,
//upperBound: 200.0,
duration: Duration(milliseconds: 5000),
);
curve = CurvedAnimation(parent: animationController, curve: Curves.easeInOut);
animation = Tween(begin: 32.0, end: 360.0,).animate(curve);
animationColor = ColorTween(begin: Colors.red, end: Colors.green,).animate(curve);
animationController.addListener(() {
print(animationController.value);
setState(() {});
});
animationController.addStatusListener((AnimationStatus status){print(status);});
super.initState();
}
@override
void dispose() {
// TODO: implement dispose
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(''),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Icon(Icons.favorite),
color: animationColor.value,
iconSize: animation.value,
onPressed: () {
animationController.forward();
switch(animationController.status){
case AnimationStatus.completed:
animationController.reverse();
break;
default:
animationController.forward();
}
}),
SizedBox(height: 57,),
RaisedButton(
child: Icon(Icons.enhanced_encryption),
onPressed: (){animationController.reverse();},
),
],
),
);
}
}