|  | 
|  | 1 | +/// | 
|  | 2 | +/// Created by NieBin on 2019年6月10日 | 
|  | 3 | +/// Github: https://github.com/nb312 | 
|  | 4 | +/// Email: niebin312@gmail.com | 
|  | 5 | +/// | 
|  | 6 | +import "package:flutter/material.dart"; | 
|  | 7 | +import 'package:flutter_widgets/const/_const.dart'; | 
|  | 8 | + | 
|  | 9 | +class AnimWidgetPage extends StatefulWidget { | 
|  | 10 | + @override | 
|  | 11 | + _AnimWidgetState createState() => _AnimWidgetState(); | 
|  | 12 | +} | 
|  | 13 | + | 
|  | 14 | +class _AnimWidgetState extends State<AnimWidgetPage> | 
|  | 15 | + with SingleTickerProviderStateMixin { | 
|  | 16 | + Animation<double> _anim; | 
|  | 17 | + AnimationController _controller; | 
|  | 18 | + | 
|  | 19 | + @override | 
|  | 20 | + void initState() { | 
|  | 21 | + _controller = | 
|  | 22 | + AnimationController(vsync: this, duration: Duration(seconds: 2)); | 
|  | 23 | + CurvedAnimation curve = | 
|  | 24 | + CurvedAnimation(parent: _controller, curve: Curves.easeIn); | 
|  | 25 | + _anim = Tween(begin: 0.0, end: 30.0).animate(curve); | 
|  | 26 | + super.initState(); | 
|  | 27 | + } | 
|  | 28 | + | 
|  | 29 | + Widget _animWidget() => _AnimWidget( | 
|  | 30 | + anim: _anim, | 
|  | 31 | + child: Text("This is Animation Widget."), | 
|  | 32 | + ); | 
|  | 33 | + | 
|  | 34 | + @override | 
|  | 35 | + Widget build(BuildContext context) { | 
|  | 36 | + return Scaffold( | 
|  | 37 | + appBar: AppBar( | 
|  | 38 | + title: Text(PageName.ANIM_WIDGET), | 
|  | 39 | + ), | 
|  | 40 | + body: Column( | 
|  | 41 | + children: <Widget>[ | 
|  | 42 | + _animWidget(), | 
|  | 43 | + FloatingActionButton( | 
|  | 44 | + child: Text("Click me."), | 
|  | 45 | + onPressed: () { | 
|  | 46 | + _controller.reset(); | 
|  | 47 | + _controller.forward(); | 
|  | 48 | + }, | 
|  | 49 | + ) | 
|  | 50 | + ], | 
|  | 51 | + ), | 
|  | 52 | + ); | 
|  | 53 | + } | 
|  | 54 | +} | 
|  | 55 | + | 
|  | 56 | +class _AnimWidget extends AnimatedWidget { | 
|  | 57 | + const _AnimWidget({Key key, Animation<double> anim, this.child}) | 
|  | 58 | + : super(key: key, listenable: anim); | 
|  | 59 | + | 
|  | 60 | + Animation<double> get size => listenable; | 
|  | 61 | + final Widget child; | 
|  | 62 | + | 
|  | 63 | + @override | 
|  | 64 | + Widget build(BuildContext context) { | 
|  | 65 | + return Container( | 
|  | 66 | + constraints: BoxConstraints.expand( | 
|  | 67 | + width: size.value * 10, | 
|  | 68 | + height: size.value * 10, | 
|  | 69 | + ), | 
|  | 70 | + color: RED_LIGHT, | 
|  | 71 | + child: child); | 
|  | 72 | + } | 
|  | 73 | +} | 
0 commit comments