import 'package:flutter/material.dart';
class AnimatedLogo extends AnimatedWidget {
// listenable类似之前写的addListener,此时可以监听animation的value
AnimatedLogo({Key key, Animation<double> animation})
: super(key: key, listenable: animation);
@override
Widget build(BuildContext context) {
final Animation<double> animation = listenable;
return Center(
child: Container(
margin: EdgeInsets.symmetric(vertical: 10),
height: animation.value,
width: animation.value,
child: FlutterLogo(),
),
);
}
}
class AnimatedLogoTest extends StatefulWidget {
@override
AnimatedLogoTestState createState() => new AnimatedLogoTestState();
}
class AnimatedLogoTestState extends State<AnimatedLogoTest>
with SingleTickerProviderStateMixin {
final Duration _duration = const Duration(milliseconds: 3000);
AnimationController controller;
Animation<double> animation;
@override
build(dynamic ) {
return new AnimatedLogo(animation: animation);
}
@override
void initState() {
super.initState();
controller = AnimationController(vsync: this, duration: _duration);
animation = Tween(begin: 0.0, end: 300.0).animate(controller);
controller.forward();
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
controller.dispose();
}
}